ASP.Net C # Razor showing encoded HTML instead of raw html

I am using JQM-DateBox which needs the following Razor markup:

@Html.TextBoxFor(m => m.From, new { @name = "mydate", @id = "mydate", @data_role = "datebox", @data_options = "{'mode':'flipbox', 'dateFormat':'dd/mm/YYYY' ,'useNewStyle':true} ") 

However, this means that:

  <input data-options=" {&#39;mode&#39;:&#39;flipbox&#39;, &#39;dateFormat&#39;:&#39;dd/mm/YYYY&#39; ,&#39;useNewStyle&#39;:true} " data-role="datebox" id="mydate" name="From" type="text" value="29/08/2013 00:00:00" /> 

I know you can use html.raw, but how do you use it in the helper?

I need to show:

{'mode':

... instead of ...

{&#39;mode&#39;:

+6
source share
2 answers

Try @Html.Raw(HttpUtility.HtmlDecode(@Html.TextBoxFor(...).ToHtmlString())) .

+10
source

TextBoxFor uses TagBuilder , which is ultimately responsible for turning ' in into &#39; (because it uses MergeAttributes with the htmlAttributes parameter htmlAttributes to the helper).

Instead of pasting an answer, go to Stop Tag Builder by running ASP.NET MVC 2 single quotes

In addition, this is not an exact question, but it is. I will leave it to others if they want to close it and give the link above.

+3
source

Source: https://habr.com/ru/post/952774/


All Articles