のように動作するカスタムHtmlHelperextensionメソッドを作成するための構文を知っている人はいますか。
<% using (Html.BeginForm()) {%>
<p>Loads of html stuff here </p>
<% } %>
私は…の線に沿って何かを考えています。
何か案は?
乾杯、
ETFairfax
のように動作するカスタム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...
}
}
次のようなメソッドが必要になります。
public static IDisposable BeginTable(this HtmlHelper html, ...)
{
// write the start of the table here
return new EndTableWriter();
}
は次のEndTableWriter
ようなものです。
private class EndTableWriter : IDisposable
{
public void Dispose()
{
// write the end of the table here
}
}