0

This is Ajax code

<script>

    $(document).ready(function () {

        $("#btnKaydet").click(function () {

            debugger
           
            var data = $("#myForm").serialize();

            $.ajax({

                type:"POST",
                url: "/Home/Olusturma",
                data: data,
                success: function (response) {

                    alert("Kayıt İşlemi Başarılı")
                }
            })
        })
    })

</script>

This is saving button code

<form id="myForm">
    <input type="button" value="Buradan Kaydet" class=" btn btn-default" id="btnKaydet" />
</form>

This is HomeController code

public ActionResult Olusturma()
    {
        KullaniciDBEntities db = new KullaniciDBEntities();

        List<Kisi> kL = db.Kisi.ToList();
        ViewBag.kisiList = new SelectList(kL, "AdSoyad", "Email", "Yas", "Konum", "Telefon", "Parola");

        return View();
    }

    [HttpPost]
    public ActionResult Olusturma(KullaniciDBEntities model)
    {
        try
        {
            KullaniciDBEntities db = new KullaniciDBEntities();
            List<Kisi> kL = db.Kisi.ToList();
            ViewBag.kisiList = new SelectList(kL, "AdSoyad", "Email", "Yas", "Konum", "Telefon", "Parola");

            Kisi k = new Kisi();

            k.ID = model.ID;
            k.AdSoyad = model.AdSoyad;
            k.Email = model.Email;
            k.Yas = model.Yas;
            k.Konum = model.Konum;
            k.Telefon = model.Telefon;
            k.Parola = model.Parola;
                

            db.Kisi.Add(k);
            db.SaveChanges();

            int SonId = k.ID;
        }
        catch (Exception ex)
        {

            throw ex;
        }
        return RedirectToAction("Listeleme");

    }

Hello everyone. When ı run my project, ı get a error. My variables seems normal but they dont show anything.It shows (null) variable in their places .How can ı fix this error? I have controller, KullaniciDBentities model and View parts.

Axe319
  • 4,255
  • 3
  • 15
  • 31

0 Answers0