Try to search your question here, if you can't find : Ask Any Question Now ?

@Helper razor enconding html

HomeCategory: stackoverflow@Helper razor enconding html
Avatarkundan asked 4 months ago

According to and some other resources @Helper blocks return a HelperResult class that Implements IHtmlString.

Being and HtmlString all the string inside the @helper blocks should not be encoded.
But I have the following scenario (the real scenario is more complex) where the html is encoded

@helper Test(){
   @(new HtmlString("<label>Test 1</label>"))
   @(new HtmlString("<label>Test 2</label>"))

When I check the view in browser I see literally <label> Test 1 .... because the Html code generate inside the @helper Test is between quotes.

But adding a RawString then it works correctly.

@helper Test(){
    @(new RawString(new HtmlString("<label>Test 1</label>").ToString()))
    @(new RawString(new HtmlString("<label>Test 2</label>").ToString()))

Taking into account that HtmlString it´s for Razor to not encode a string and @Helper returns HtmlString, I don´t get why I need to add RawString to render correctly the html code on browser.

1 Answers
Best Answer
AvatarAmit answered 4 months ago
Your Answer

17 + 2 =

Popular Tags

WP Facebook Auto Publish Powered By :