I have a form that I would like the users to submit to the server. The (simplified) model looks like that:
public class MyData
{
public int MyInt { get; set; }
public ICollection<ComplexObject> MyArray { get; set; }
}
public class ComplexObject
{
public int MyComplexObjectInt { get; set; }
public string MyComplexObjectString { get; set; }
}
The controller action that receives this object looks like this:
[HttpPost]
public ActionResult Create(MyData model)
{
...
}
I have a "ComplexObject" array in the client side (jQuery) that I populate with user's input.
The problem: How can I set the "MyArray" value to contain the jQuery array values and retrieve this array in the controller?
Note: I've googled this issue quite a bit and all the solutions I've found talked about ajax. I'm not interesting in these solutions and I wonder if it can be done without ajax.
Thanks.
process.aspxyou just need to use<form action="process.aspx">instead of$.ajax('process.aspx').<input type="hidden" name="MyInt" value="<%= MyInt %>"> <input type="hidden" name="ComplexObject" value="" />, then set the value of ComplexObject input toJSON.stringify( jQueryArray )before submitting the form.