开发者

How to send jquery list to mvc controller

I`m completely new to MVC. I have to do the following:

I have 4 lists a, b, c, d that are filled dynamically, based on add or delete button clicked. I need to send the values of the list to the controller when submit button is cli开发者_如何学Gocked. How can I do that? Please give me an example ot a link where I will have an example.


Here's a handy plugin for serializing lists. Then you can serialize the data like so: $('#a').serializelist() and pass that to your back end and treat it however you'd like.

http://github.com/botskonet/jquery.serialize-list

Edit: More specifically...

$('.submit').click(function() {
  $.ajax({
    type: "POST",
    url: "process.php",
    data: $('#a').serializelist(),
    success: function(){
     alert( "Success!");
    }
  });
});


One option would be to iterate through each item and build the json one item at a time when you submit. The other being you could build the json when the user clicks the buttons to add the items to the list. You could add code to your click event to build your json and store it in a variable or dom element then use that variable or dom element in your submit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜