1
Vote

(bug) Everything gets encoded

description

It seems that everything that I try and add to the template gets encoded. How can I add html elements to the template the same kind of way that someone might do it via @Html.LabelFor(d => d.Id)?

My Template
public class MyTemplateBase : HtmlTemplateBase<Person>
{
    public string LabelFor(Expression<Func<Person, string>> ex)
    {
        return "<label for=\"Id\">" + ex.Compile().Invoke(this.Model) + "</label>";
    }
}
Output html AFTER rendering
<label for="Id">1</label>

Expected html
<label for="Id">1</label>

Razor View
        var html = Razor.Parse<Person>(@"
<!DOCTYPE html>

<html>
<head> <meta name=""viewport"" content=""width=device-width"" /> <title>Index</title> </head> <body>
<div>
   @LabelFor(d => d.Id)
</div>
</body>
</html>
        ", new Person() { Id = "1", Name = "Dude" });

comments

DotNetRockStar wrote Mar 25, 2014 at 9:07 PM

btw. the "output html AFTER rendering" is the Html encoded value, not what it has up there (forum did that after I typed it)