0

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")%>

助けてくれてありがとう。

ETFエアファックス

4

1 に答える 1

1

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.
    }
}
于 2009-10-27T14:54:26.787 に答える