Gustavo Caldeira
Gustavo Caldeira

Reputation: 21

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, Type TypeModel)
{
    return "My Helper" + DevExpress.Web.Mvc.UI.ExtensionsFactory.Instance.TextBox(settings =>
            {
                settings.Name = att.Nome;
            }).GetHtml()
}

Upvotes: 1

Views: 944

Answers (2)

Filip Ekberg
Filip Ekberg

Reputation: 36287

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);
}

Upvotes: 1

SLaks
SLaks

Reputation: 887459

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.

Upvotes: 0

Related Questions