Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
$.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

C#
var name = $("Name").val();
         var age = $("Age").val();
         var acorns = $("Acorns").val();
         var gender = $("Gender").val();
         var hobby = $("Hobby").val();
//I gues for dynamic data i have to use loop and then passing all data to dynamic 
//
//generated fields then

         // build json object
         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.
Posted
Updated 6-Aug-15 8:38am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900