3
I came across the following situation, in one of the views
I have a search ground:
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
@Html.TextBox("parametroProcura")
</div>
<button type="submit" class="btn btn-default">Pesquisar</button>
</form>
Reading, and seeing some videos on the internet, I realized that the staff puts the search field within a @Html.BeginForm
:
@using (Html.BeginForm())
{
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
@Html.TextBox("parametroProcura")
</div>
<button type="submit" class="btn btn-default">Pesquisar</button>
</form>
}
However, the search works in both cases, so... why use @Html.BeginForm
?
Adding: It prevents typing errors, development-time validation, and also references your target endpoints by types. So, if you change the
Route
of aAction Controller
, all theForms
that make reference to it will render to the new route without additional effort.– Thiago Lunardi
Perfect, one last doubt, I can use how many
@Html.BeginForm()
per view? or is unlimited?– Thomas Erich Pimentel