gpt4 book ai didi

asp.net - Html.BeginForm() 扩展类型

转载 作者:行者123 更新时间:2023-12-02 17:48:37 25 4
gpt4 key购买 nike

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

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

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

<% } %>

我正在考虑一些类似的事情......

有什么想法吗?

干杯,

ETFairfax

最佳答案

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

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...
}
}

关于asp.net - Html.BeginForm() 扩展类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1648711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com