0

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
  • 3
    Why not put the form tag outside the partial views? Commented Jul 26, 2013 at 8:22
  • Really, why not :-) Thanks, Blade0rz Commented Jul 26, 2013 at 8:25

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I tried it. @Html.Partial("Partial1", BigModel) worked for me, otherwise BigModel.SmallerPartN is null in POST action method.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.