ETF*_*fax 6 asp.net asp.net-mvc html-helper
有没有人知道创建自定义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...
    }
}
| 归档时间: | 
 | 
| 查看次数: | 1232 次 | 
| 最近记录: |