Html.BeginForm()扩展类型 [英] Html.BeginForm() type of extension

查看:116
本文介绍了Html.BeginForm()扩展类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道语法以创建一个功能类似..定制HtmlHelperextension方法

Does anyone know the syntax for creating a custom HtmlHelperextension method which behaves like..

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

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

<% } %>

我沿着....

I'm thinking of something along the lines of....

&LT;%使用(Html.BeginTable(列标题1,列标题2)){%>

<% using (Html.BeginTable("Column Heading 1", "Column Heading 2")) {%>

&LT;%}%>

任何想法?

干杯,

ETFairfax

ETFairfax

推荐答案

您需要创建一个类实现的IDisposable 界面,返回,从你的的HtmlHelper

You need to create a class that implements IDisposable interface and return that from your 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...
    }
}

这篇关于Html.BeginForm()扩展类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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