I’m developing an ASP.NET MVC app and I’m a bit curious if anyone can tell me if there’s a better way than this to submit selected options with the rest of the form data?
var lstOption1 = $('#lstOption1 :selected').attr("optionId1");
var lstOption2= $('#lstOption2 :selected').attr("optionId2");
var formData = $(this).serialize()
+ "&lstOption1 =" + lstOption1 +
+ "&lstOption2=" + lstOption2;
$.post($(this).attr("action"), formData, function(res)
{
});
Thanks
Dave
I have an MVC page that needs to submit the selected value from a group of radio buttons.
I use:
To make an array of their names and values
and then post it with jQuery’s ajax() to the MVC controller
Which sends the data across as native JSON data.
You can then capture the response stream and de-serialize it into the native C#/VB.net object and manipulate it in your controller.
To automate this process in a lovely, low maintenance way, I advise reading this entry that spells out most of native, automatic JSON de-serialization quite well.
Article on MVC JSON deserialization
… and because Stack OVerflow won’t let me post 2 links because I’m “new” you will have to google “jquery-json google code” to find the jQuery JSON plug-in I’m using.
I hope this helps!