Pregunta

Tengo un control de usuario personalizado llamado ErrorNotificationBox. Para colocar eso en mi página hago lo viejo ...

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

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

¿Es posible extender HtmlHelper para incluir mi control de usuario? Es decir ...

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

Muchas gracias por cualquier ayuda.

ETFairfax

¿Fue útil?

Solución

La mayoría de los métodos en html helper son métodos de extensión. Puede agregar fácilmente el suyo.

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 bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top