开发者

How build Custom Helper using other helpers inside the code

I'm creating a custom helper to automate some code in my application. I'd like now how display a control in my helper. When I return the GetHTML() method, the page display the HTML like a plain text. When I use the Render() method the control is rendere in body, out of order.

public static string EntityForm(this HtmlHelper helper,开发者_JAVA百科 Type TypeModel)
{
    return "My Helper" + DevExpress.Web.Mvc.UI.ExtensionsFactory.Instance.TextBox(settings =>
            {
                settings.Name = att.Nome;
            }).GetHtml()
}


Use HtmlString, this way it does not encode the output.

Example from inside a view

@(new HtmlString("<div>some html</div>"))

Changing your Html Helper

Try changing your method to the following:

public static HtmlString EntityForm(this HtmlHelper helper, Type TypeModel)
{
    var html = "My Helper" + DevExpress.Web.Mvc.UI.ExtensionsFactory.Instance.TextBox(settings =>
            {
                settings.Name = att.Nome;
            }).GetHtml();

    return new HtmlString(html);
}


Razor will escape all strings written to the page.
You need to change your helper method to return an HtmlString so that Razor won't escape it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜