HtmlHelper拡張機能-ユーザーコントロール
-
06-07-2019 - |
質問
ErrorNotificationBoxというカスタムユーザーコントロールがあります。私のページにそれを置くために、私は古いことをします...
<%@ Register Src="~/PathTo/ErrorNotificationBox.ascx" TagName="ErrorNotificationBox" TagPrefix="uc" %>
<uc:ErrorNotificationBox Runat="server" id="myEnb" Caption="My Test Caption" />
HtmlHelperを拡張してユーザーコントロールを含めることは可能ですか?つまり...
<%= Html.ErrorNotificationBox("My Test Caption")%>
ご協力ありがとうございます。
ETFairfax
解決
htmlヘルパーのメソッドのほとんどは拡張メソッドです。簡単に独自のものを追加できます。
public static class MyExtensions
{
public static string ErrorNotificationBox(this HtmlHelper helper, string caption)
{
//generate and return the html for your error box here.
// loading and returning an instance of a user control (.ascx)
// as a string is difficult. You may find it easier to
// create the html with a string builder.
}
}
所属していません StackOverflow