문제

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

도움이 되었습니까?

해결책

HTML 헬퍼의 대부분의 방법은 확장 방법입니다. 당신은 자신의 것을 쉽게 추가 할 수 있습니다.

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