I have problem with custom html helper. I try to build a helper, using TagBuilder but I'm unable to close it.

Here is my code:

 public static HtmlString CustomHelper(this HtmlHelper htmlHelper,
        string id)
        var contentDiv = new TagBuilder("div");
        contentDiv.MergeAttribute("style", "display:inline-block");

        var input = new TagBuilder("input");
        input.MergeAttribute("type", "hidden");
        input.MergeAttribute("id", id);
        input.MergeAttribute("value", "Cat");

        contentDiv.InnerHtml += input;

        return new HtmlString(contentDiv.ToString(TagRenderMode.EndTag));

But the result of it looks like:

enter image description here

Something is wrong but I can't find out what, I'm missing it. Even closing input tag is wrong. I have checked version of dlls and have tried with MvcHtmlString ect. Also the TagRenderMode doesn't work at all.

Thanks for the help.

Best regards.

Related posts

Recent Viewed