We are trying to submit multiple forms with one Ajax call (jQuery) to an ASP application.
We use the following jQuery code:
var formContainer = { Form1 : form1.serialize(), Form2 : form2.serialize() } $.ajax({ type: "POST", url: '@Url.Action("CreateModel", "Controller")', data: formContainer, success: function (result) { } });
On the server, we get the following in the Request.Form property:
Key : Value Form1 : All serialized form elements for Form1 Form2 : All serialized form elements for Form2
We usually use the following method, so ASP automatically creates an object with the correct property value:
public ActionResult CreateModel(ClassForForm1 obj)
But since the two forms are sent together, modelbinder cannot bind and build the class. Therefore, for this action, we want the builder to use the values ββin Request.Form ["Form1"].
We cannot use a custom mediator, because we use an external library (DevExpress, they wrote their own implementation above this).
We use the MEF structure to add functionality (these functions are added as forms per view). For this reason, we do not know what to expect from the backend. Therefore, writing a ViewModel shell is unacceptable.
Functionality for processing data of other forms will be stored inside other modules.
Any solutions are welcome!
Thanks in advance.
javascript jquery ajax asp.net-mvc model-binding
Stefan koenen
source share