0

我有一个名为 ErrorNotificationBox 的自定义用户控件。为了把它放在我的页面上,我做了旧的......

<%@ Register Src="~/PathTo/ErrorNotificationBox.ascx" TagName="ErrorNotificationBox" TagPrefix="uc" %>

<uc:ErrorNotificationBox Runat="server" id="myEnb" Caption="My Test Caption" />

是否可以扩展 HtmlHelper 以包含我的用户控件?IE..

<%= Html.ErrorNotificationBox("My Test Caption")%>

非常感谢您的帮助。

ETF费尔法克斯

4

1 回答 1

1

html helper 中的大部分方法都是扩展方法。您可以轻松添加自己的。

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 回答