2

I have a MVC 4 project in C# and the controller calls the business layer for some validation which returns a string. This string if not null will return back to the View in Viewbag and display in a dialog which is plan text. The validation string contains some message and also an amount with pound sign symbol (£). When it is displayed in the view, the £ symbol shows as £

What do I need to do so £ sign displayed as the currency symbol besides using Html.Raw (since it's not a good practice to put this in Razor view)?

Edit: htmldecode is not the right answer. I need a way to not encode the string again. Either Html.Raw or MvcHtmlString.Create works

user1214916
  • 239
  • 2
  • 17
  • 1
    If you trust the string values, you can use `Html.Raw` which does not do any html encoding – Shyju Aug 08 '18 at 18:35
  • BTW, you can send your custom error message via ModelStateDictionary as well. – Shyju Aug 08 '18 at 18:39
  • Possible duplicate of [How can I decode HTML characters in C#?](https://stackoverflow.com/questions/122641/how-can-i-decode-html-characters-in-c) – Sander Aug 08 '18 at 18:39

1 Answers1

0

You can use the HttpUtility to decode within your view:

@HttpUtility.HtmlDecode(Model.Value)
Jason W
  • 13,026
  • 3
  • 31
  • 62