Расширение 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