JQuery presents form and its model to the controller
3 answers
If you want to pass your complex model directly to a controller method from jQuery, take a look at this question .
+2
source to share
Create your controller action with FormCollection declared. Then just call UpdateModel which will map your form properties to your object.
public ActionResult MyAction(FormCollection form)
{
MyDomainObject a = //possibly get from repository
try
{
UpdateModel(a);
...
Your kind
<form id='my-form' action='post' method='/MyController/MyAction'>
//form elements
</form>
And here is some javascript.
$(document).ready(function()
{
var f = $('my-form');
var action = f.attr('action');
var serializedForm = f.serialize();
$.post
(
action,
serializedForm,
function()
{
//anything after the form submit
}
);
}
+4
source to share