如何使用HtmlHelper.BeginForm()工作? [英] how does using HtmlHelper.BeginForm() work?
问题描述
行,所以我想知道如何
<% using (Html.BeginForm()) { %>
<input type="text" name="id"/>
<% } %>
农产品
<form>
<input type="text" name="id"/>
</form>
在结束;
即它是如何添加&LT; /表及GT?我看着在codePLEX,并在的HtmlHelper没有找到它。有一个端部结构的方法,但如何上面知道打电话了吗?
namely how does it add the </form>
at the end? I looked in codeplex and didn't find it in the htmlhelper. There is a EndForm method, but how does the above know to call it?
的原因是我要创建的HtmlHelper扩展,但不知道该怎么收出上使用的结束。
The reason is I want to create an htmlhelper extension, but don't know how to close out on the end of a using.
任何帮助将是AP preciated:)
Any help would be appreciated :)
推荐答案
BeginForm
返回的IDisposable
它调用端部结构
在的Dispose
。
当你写使用(Html.BeginForm()){...}
,编译器生成一个最后
块调用的Dispose
,这反过来又调用端部结构
并关闭&LT;形式&GT;
标记。
When you write using(Html.BeginForm()) { ... }
, the compiler generates a finally
block that calls Dispose
, which in turn calls EndForm
and closes the <form>
tag.
您可以通过编写自己的类复制这种效果实现的IDisposable
。
You can duplicate this effect by writing your own class that implements IDisposable
.
这篇关于如何使用HtmlHelper.BeginForm()工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!