views:

74

answers:

2

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 clicked. How can I do that? Please give me an example ot a link where I will have an example.

+2  A: 

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!");
    }
  });
});
Kelli Shaver
he is actually looking how to pass to the controller not how to serialize them, right?
Sarfraz
I need to know how to pass the data using jquery
That's what the $.ajax call does. The serializelist() function just groups it all in a handy string of arguments to be passed. Unless I'm misunderstnding what you're asking.Check the jquery API docs for AJAX http://api.jquery.com/category/ajax/I'm not sure what MVC framework you're using, but if it happsns to be Rails, there's a great railscast on how to submit data via AJAX. http://railscasts.com/episodes/136-jquery - It's pretty good info in general. You can pretty much apply the same principles to any NVC framework.
Kelli Shaver
A: 

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.

WVDominick