加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 21:05:26 所属栏目:asp.Net 来源:网络整理
导读:有没有人知道创建自定义 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...
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读