asp.net – Html.BeginForm()类型的扩展名

有没有人知道创建自定义 HtmlHelperextension方法的语法,其行为类似于.. % using (Html.BeginForm()) {%pLoads of html stuff here /p% } % 我正在考虑…… 有任何想法吗? 干杯, ETFairfax 您需要创建一个实现IDisposable接口的类,并从HtmlHelper返回该接口.

有没有人知道创建自定义
HtmlHelperextension方法的语法,其行为类似于..

<% using (Html.BeginForm()) {%>

<p>Loads of html stuff here </p>

<% } %>

我正在考虑……

有任何想法吗?

干杯,

ETFairfax

解决方法

您需要创建一个实现IDisposable接口的类,并从HtmlHelper返回该接口.

public static class HtmlHelperTableExtensions {
    private class TableRenderer : IDisposable {
        HtmlHelper html;
        public TableRenderer(HtmlHelper html) {
           this.html = html;
        }
        public void Dispose() {
           HtmlHelperTableExtensions.EndTable(html);
        }
    }
    public static IDisposable BeginTable(this HtmlHelper html) {
        // print begin table here...
        return new TableRenderer(html);
    }
    public static void EndTable(this HtmlHelper html) {
        // print end table here...
    }
}

作者: dawei

【声明】:滨州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部