ASP.NET MVC Razor, Html.BeginForm, using 语句 [英] ASP.NET MVC Razor, Html.BeginForm, using statement
问题描述
对于 ASP.NET MVC 应用程序,谁能向我解释为什么对 Html.BeginForm
的调用以语句 @using
开头?
For an ASP.NET MVC application, can someone explain to me why calls to Html.BeginForm
begin with the statement @using
?
示例 -
@using (Html.BeginForm()) {
@using (Html.BeginForm()) {
//Stuff in the form
}
我认为 @using
语句用于包含命名空间.谢谢!
I thought @using
statements are for including namespaces.
Thanks!
推荐答案
使用声明 提供了一种方便的语法,可确保正确使用 IDisposable
对象.由于 BeginForm
助手实现了 IDisposable
接口,您可以将 using
关键字与它一起使用.在这种情况下,该方法会在语句的末尾呈现结束 </form>
标记.您也可以使用 BeginForm
而不使用 using
块,但是您需要标记表单的结尾:
Using Statement provides a convenient syntax that ensures the correct use of IDisposable
objects. Since the BeginForm
helper implements the IDisposable
interface you can use the using
keyword with it. In that case, the method renders the closing </form>
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(); }
这篇关于ASP.NET MVC Razor, Html.BeginForm, using 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!