Вопрос

У меня есть собственный пользовательский элемент управления 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.
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top