MVC more than one form to submit

I have a standard form view in MVC, and I need to place a user control, in this case Create, inside a BeginForm, as shown below:

When the problem is that Create ascx when submitting the form does not start its action in the controller, what am I doing wrong?

<% using (Html.BeginForm())
   {%>
<fieldset>
    <legend>Tax</legend>
    <p>
        <label for="Name">
            Name:</label>
        <%= Html.TextBox("Name", Model.Tax.Name) %>
        <%= Html.ValidationMessage("Name", "*") %>
    </p>
    <p>
        <%  Html.RenderAction("Create", "Mileage"); %>
    </p>
    <p>
        <input type="submit" value="Save" />
    </p>
</fieldset>
<% } %>

Here is Create.ascx

<% using (Html.BeginForm())
   {%>
<fieldset>
    <p>
        <label for="Distance">
            Distance:</label>
        <%= Html.TextBox("Distance", Model.Mileage.Distance)%>
        <%= Html.ValidationMessage("Distance", "*") %><span class="field-validation-error"
            id="field-validation-error-distance">*</span>
    </p>
</fieldset>
<% } %>
+3
source share
2 answers

You have nested forms in your resulting HTML. This will not work properly. Remove the shape from the inside view. The internal view will be incomplete, so if you use it as a standalone, you must make it general and create another view that simply opens the form, displays the internal view and closes the form.

: . , (, Html.TextBox( "Mileage.Distance" ).

+3

HTML. . : FORM

FORM. , FORM .

, , .

+1

Source: https://habr.com/ru/post/1719002/


All Articles