ASP.NET MVC Razor, Html.BeginForm, using statement

后端 未结 3 846
星月不相逢
星月不相逢 2020-12-10 13:49

For an ASP.NET MVC application, can someone explain to me why calls to Html.BeginForm begin with the statement @using?

Example -

3条回答
  •  攒了一身酷
    2020-12-10 14:21

    Using Statement provides a convenient syntax that ensures the correct use of IDisposableobjects. Since the BeginForm helper implements the IDisposable interface you can use the using keyword with it. In that case, the method renders the closing tag at the end of the statement. You can also use the BeginForm without using block, but then you need to mark the end of the form:

    @{ Html.BeginForm(); }
        //Stuff in the form
    @{ Html.EndForm(); }
    

提交回复
热议问题