我试图创建一些Html Helpers,它们将具有开放标签和闭合标签,并包含其他内容,就像Html.BeginForm一样。 例如,在Razor中我们可以使用Html.BeginForm Helper,它的语法如下:
@using (Html.BeginForm())
{
}
这段代码将包含花括号中的内容在<div> 和 </div> 之间。我解决了打开和关闭标签以及包含内容的唯一方法是使用两个html helper。我定义了两个html helper:
public static MvcHtmlString StartForm(this System.Web.Mvc.HtmlHelper helper)
{
return new MvcHtmlString("<form>");
}
public static MvcHtmlString EndForm(this System.Web.Mvc.HtmlHelper helper)
{
return new MvcHtmlString("</form>");
}
然后我使用以下示例中的助手:
@Html.StartForm()
contents
@Html.EndForm()
但我希望能够创建一个HTML助手,使其在视图中具有以下格式:
@using (Html.MyForm())
{
<text>contents</text>
}
有人能帮我解决这个问题吗?因为我甚至不知道该如何搜索它。
MvcForm
的类来完成。 - vbn