There is a huge object which I need to edit in different tabs. Each tab is a partial view with a single form inside. Is it possible to submit data from all the partial forms with a single submit button? I would like to have combined model object in my POST action method to save it further.
2 Answers
In your page, just make sure that all your partial views are wrapped by the main form:
@model MyNamespace.BigModel;
@using (Html.BeginForm())
{
<!-- Other tab code would go around here -->
@Html.Partial("Partial1", BigModel)
@Html.Partial("Partial2", BigModel)
@Html.Partial("Partial3", BigModel)
<!-- Other tab code would go around here -->
}
Then a submit button anywhere within the form would submit all the data.
1 Comment
ohavryl
Ok, I tried it. @Html.Partial("Partial1", BigModel) worked for me, otherwise BigModel.SmallerPartN is null in POST action method.
You could use something on the client side to do this (for example using jQuery):
$('#button-to-submit-everything').click(function () {
$('form').submit();
});
This would submit an individual post to each partial view.
If you only want one post then I believe you would need to have only one form encompassing all of your partial views.