سؤال

ولدي تحكم المستخدم مخصص يسمى 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

هل كانت مفيدة؟

المحلول

ومعظم الطرق في المساعد أتش تي أم أل هي أساليب الإرشاد. يمكنك بسهولة إضافة الخاصة بك.

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