Posts

Showing posts from December, 2016

post form data and bind with model : using jquery ajax in mvc

There are multiple ways of posting data from view to controller using jquery + ajax in mvc 1. post data by assigning parameters one by one and bind it with model manually 2. post data by serializing form and automatically binding with model 3. post data by assigning parameters one by one + making custom class and assigning data to its variables which are named similarly as that of model Method 1:     $.ajax({         url: "/Controller/SubmitAction",         type: "POST",         dataType: "text",         data: { name: _name, age: _age, id: _id },         success: function (response) {             alert("Success");         },         error: function () {             alert("Error");         }     }); public JsonResult SubmitAction(string name, string age, int id) {       try       {             Person obj = context.Person.FirstOrDefault(x=>x.id = id);             obj.Name = name;             obj.Age = age;