My web page have a button and a form,I use @Html.BeginForm to produce the form and when I click the button,I will jump to the login page.To my surprise,when I click the button,the form post to my controller automatically.But when I use @using (Html.BeginForm,it seems OK.
My web page
<button >logout</button>
@Html.BeginForm("ExportFile", "Student", new { id = "exportForm" }))
{
@Html.Hidden("year")
@Html.Hidden("fileName")
}
My new web page will work well
<button >logout</button>
@using (Html.BeginForm("ExportFile", "Student", new { id = "exportForm" })))
{
@Html.Hidden("year")
@Html.Hidden("fileName")
}
I find the different HTML is System.Web.Mvc.Html.MvcForm):
<form id="exportForm" method="post" action="/Student/ExportFile">
System.Web.Mvc.Html.MvcForm) {
<input id="year" type="hidden" value="" name="year">
<input id="fileName" type="hidden" value="" name="fileName">
}
What is the difference between then?Someone teach me to add @{Html.EndForm();} when I using @Html.BeginForm,but it seems not work.May be it works in MVC3.