Frage

Ich habe eine benutzerdefinierte Steuerung namens ErrorNotificationBox. Zu setzen, die auf meiner Seite ich die alten ...

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

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

Ist es möglich, Htmlhelper zu erweitern, um meine Benutzersteuerung enthalten? Das heißt ...

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

Vielen Dank für jede Hilfe.

ETFairfax

War es hilfreich?

Lösung

Die meisten Methoden in HTML-Helfer sind Erweiterungsmethoden. Sie können Ihre eigenen leicht hinzufügen.

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.
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top