Kyle
Kyle

Reputation: 33691

Handle variable number of dynamic input fields in ASP.NET MVC?

I've done a lot of C# programming but I haven't touched much web until recently. One thing I've been struggling a little bit with, and really think there must be a better way I don't know about, is the right(a few of the better ways?) way to send the data in a form to a server.

I'm using MVC4 / C #, and I'm working on an html form that will be at least 18 inputs, some with multiple selections, and the ability for users to click 'add another' to a certain spot, and could make the amount of input fields 30+.

Is there any neat way to package this into some sort of javascript object, and receive it as a object in c#?

I would prefer to not do a post with the form, since I want to use AJAX and not have the page refresh.

In the only other form I have done so far in this project, there was about 6 inputs, but each one was optional. I built a queryurl and used jquery. Just this seemed like more of a pain than it needed to be and it's much smaller.

$.get(apiLink, function (response) {
        $("#SearchResults").html(response);
    });

Upvotes: 4

Views: 600

Answers (1)

pollirrata
pollirrata

Reputation: 5286

You can create a JSON object with all the inputs you have, and then parse it on your controller using JSON.NET

Upvotes: 2

Related Questions