ASP.NET MVC剃刀,Html.BeginForm,using语句 [英] ASP.NET MVC Razor, Html.BeginForm, using statement
问题描述
有关ASP.NET MVC应用程序,为什么调用 Html.BeginForm
可有人向我解释与说法 @using $开头C $ C>?
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
界面,你可以使用使用
关键字吧。在这种情况下,该方法使得关闭< /形式为GT;
在语句的结束标记。您也可以使用 BeginForm
没有使用
块,但你需要标记形式的末尾:
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剃刀,Html.BeginForm,using语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!