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
المحلول
ومعظم الطرق في المساعد أتش تي أم أل هي أساليب الإرشاد. يمكنك بسهولة إضافة الخاصة بك.
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