HtmlHelper Extensão - Controle do Usuário
-
06-07-2019 - |
Pergunta
Eu tenho um controle de usuário personalizada chamado ErrorNotificationBox. Para colocar isso na minha página que eu fazer o velho ...
<%@ Register Src="~/PathTo/ErrorNotificationBox.ascx" TagName="ErrorNotificationBox" TagPrefix="uc" %>
<uc:ErrorNotificationBox Runat="server" id="myEnb" Caption="My Test Caption" />
É possível estender HtmlHelper para incluir meu controle de usuário? Ou seja ...
<%= Html.ErrorNotificationBox("My Test Caption")%>
Muito obrigado por qualquer ajuda.
ETFairfax
Solução
A maioria dos métodos em html helper são métodos de extensão. Você pode facilmente adicionar seu próprio país.
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.
}
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow