如何使用HtmlHelper.BeginForm()工作? [英] how does using HtmlHelper.BeginForm() work?

查看:75
本文介绍了如何使用HtmlHelper.BeginForm()工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

行,所以我想知道如何

<% 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆