Using Html.BeginForm inside section razor layout
I have a _Layout page with two sections: @RenderSection("LeftContent", False) and @RenderSection("MainContent", False)
All works perfectlly with another page that uses this Layout, except submit don do anything, I mean submit do not call HttpPost:
@ModelType iSAM.PROVINCIA
@Code
ViewData("Title") = "Create"
Layout = "~/Views/Shared/_Layout.vbhtml"
End Code
@section LeftContent
Add navigation menu
End Section
@section MainContent
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@Using Html.BeginForm()
@Html.ValidationSummary(True, "Error al crear el registro. Revise los errores e intente nuevamente.")
@<fieldset>
<legend>Fields</legend>
<p>
@Html.LabelFor(Function(Model) Model.DESC_PROVINCIA, "Name:")
@Html.TextBoxFor(Function(Model) Model.DESC_PROVINCIA, New With {.style = "text-transform:uppercase"})
</p>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
@<div>
@Html.ActionLink(" ", "ListProvincias", "_Layout", New With {.area = ""}, New With {.class = "imgBack", .title = "Back"})
</div>
End Using
End Section
If I left the code outside MainContent section it works. There's a way to开发者_运维知识库 make it work inside this section?
Regards.<input type="submit" value="Save" runat="server" />
Remove the runat="server" and it should work fine. Old web-form habits die hard = )
Edit:
While the above is an issue, it wasn't the root of the problem. The issue here was there was a @Html.BeginForm
in BOTH the MasterPage and inside the content section, meaning two forms were defined and thus caused the one defined in the content section to not function.
精彩评论