Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@using block before @Html.BeginForm

I was wondering why enclose @Html.BeginForm() in @using block like below. Does it matter if I don't use @using block?

@using (Html.BeginForm())
{
}
like image 750
KrishnaDhungana Avatar asked Dec 08 '22 12:12

KrishnaDhungana


1 Answers

Does it matter if I don't use @using block?

Yes, it will matter. The BeginForm method returns an IDisposable and in its Dispose method it renders the closing </form> tag. So if you don't place it in a using statement you will have to generate the closing form tag yourself:

@Html.BeginForm()
...
@Html.EndForm()

which is uglier.

like image 62
Darin Dimitrov Avatar answered Dec 11 '22 11:12

Darin Dimitrov