0

I created a form. I want to do a post save method.

He records but records the same data twice. How can I solve this problem?

I have to solve the double registration problem. I'm pushing the button once. When I go through Debug step by step, it goes twice on the same line. When I control the db as a top-down, I see that you double-logged.

HTML:

<div class="portlet-body form">
       @using (Ajax.BeginForm("TalepTurKaydet", "MasterEducationController",
         new AjaxOptions { HttpMethod = "post", OnSuccess = "TalepTurKaydet" },
                                                            new { @class = "" }))
        {
            @Html.ValidationSummary(true)
            <div class="form-body">
                <div class="row">               
                    <div class="col-md-12" style="margin-left: 20px">

                    <div class="col-md-6">
                        <div class="form-group">
                            <label class="control-label col-md-3">Açıklama: </label>
                            <div class="col-md-9">
                                <textarea id="Aciklama" name="Aciklama" class="col-md-12" style="resize: none;" rows="5" placeholder="Açıklama"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="clearfix"></div><br /><br />
                </div>
                <div class=" form-actions right">
                    <button type="button" class="btn green btnPrevious"><i class="fa fa-angle-double-left"></i>Geri</button>
                    <button id="talepOlustur" type="submit" class="btn blue"><i class="fa fa-check"></i> Talep Oluştur</button>
                </div>
            </div>
        }
    </div>

Controller:

public ActionResult MezuniyetBilgiKaydet(MezuniyetBilgi model)
        {
            List<MezuniyetBilgi> list = null;
            model.KullaniciId = GetUye().kullaniciID;
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(ApiAdress.API_URL);

                var responseTask = client.PostAsJsonAsync("apiMasterProgramEducation/MezuniyetBilgiKaydet", model);
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync<List<MezuniyetBilgi>>();
                    readTask.Wait();

                    list = readTask.Result;
                    model = list.FirstOrDefault();

                    return Json(new
                    {
                        Success = true,
                        data = model,
                        Message = SuccessMessage.MEZUNIYET_BILGISI_INSERT_MESSAGE,
                        JsonRequestBehavior.AllowGet
                    });

                }

            }
        }

API:

   public IHttpActionResult MezuniyetBilgiKaydet(MezuniyetBilgi model)
        {
            List<MezuniyetBilgi> detay = new List<MezuniyetBilgi>();
            try
            {
                using (var ctx = new ktdbEntities())
                {
                    if (model != null)
                    {
                        var query = ctx.mezuniyetBilgisiEkle(model.KullaniciId, model.MezuniyetTarih, model.MezunOlduguOkul,
                            model.MezunOlduguFakulte, model.MezunOlduguBolum, (float)(model.MezuniyetNotu));

                        model.Output = true;
                        detay.Add(model);
                        return Ok(detay);
                    }

                }
            }
            catch (Exception e)
            {
                model.Output = false;
                model.Message = e.Message;
                detay.Add(model);

            }
            return Ok(detay);
        }
3
  • WHICH LINE?! There's a lot of code there - don't make us guess. Commented Dec 28, 2017 at 6:00
  • So there are no other post backs going on beside the one you have shown? Commented Dec 28, 2017 at 6:03
  • I solved the problem. There is only one post, but the _Layout page has more than one jquery script path, so it was double-registering. Removing more query scripts has been resolved in the query. Commented Dec 28, 2017 at 6:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.