I have a page which contains dynamic elements ,textboxes,radio buttons ,dropdownlists etc , now in Asp.net MVC i can just pass a model to my view and on submitting that page i have the values of all these elements in my model.
For this i have to reload my page , but i dont want to load my page , I just want to do this using ajax/json.
But what i currenlty know is by posting form values using Ajax i have to mark all add all values one by one to the data attribute like
$.ajax({
url:@Url.Action("_CreateFeature","Module")',
data: {
Id:id,
Name:name,
...etc etc
},
dataType: "html",
success: function (data) {
$("").empty();
$("").append(data);
},
or if i use Json then i have to pass all my form data to json format like this is what i got from some tutorial
var name = $("Name").val();
var age = $("Age").val();
var acorns = $("Acorns").val();
var gender = $("Gender").val();
var hobby = $("Hobby").val();
var squirrel = {
Name: name,
Age: age,
etc..etc
};
$.ajax({
type: "POST",
url: "home/PostSquirrel",
traditional: true,
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(squirrel),
success: function (data) { console.log(data) },
error: function (data) { console.log(data) }
});
Is there any other way by which i can post this data and can get the advantage of model binding , since in both these approaches the code is very dirty and dubugging becomes an headache.
I have experience on working Ajax/json/Jquery so ,so if this is not possible in jquery/ajax/json level then i can also think to use Angular js or something similiar to that although i have to first give my time to learn these.,plz suggest me something according to my requirement.