4

I need to display a data from a database which contains strings like & or «. When I try to display them through Html.Raw or Html.Encode, I've got dublicates values like & for Html.Raw and also bad output for Html.Encode.

What should I try? I use Razor syntax.

Example string: Hello, my name is Junior & I hate «bugs».

6
  • I think what you want to do is Decode(), not either of the above. And doesn't MVC automatically do that with the <%: %> syntax? Commented May 17, 2012 at 17:49
  • @Cory: <%: %> is not Razor syntax... Commented May 17, 2012 at 17:50
  • @JeremyHolovacs: Ahh, thanks. I've not had the pleasure of doing much MVC work :( Commented May 17, 2012 at 17:51
  • 2
    the @Html.Raw(string) should be the proper syntax. Are you sure the string data in the database is not already escaped? Commented May 17, 2012 at 17:57
  • Yeah, you are right. I've got a bad string in a database. Commented May 17, 2012 at 18:04

1 Answer 1

12

As per the comments at the top:

the @Html.Raw(string) should be the proper syntax. Are you sure the string data in the database is not already escaped?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.