6

I'm using the 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 renders as:

 <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 within a helper?

I need to show:

{'mode':

...instead of...

{&#39;mode&#39;:

Imad Alazani
  • 6,688
  • 7
  • 36
  • 58
Mark
  • 7,778
  • 24
  • 89
  • 147
  • The code you show as input does not produce the html you show as output. Was there a copy paste error? The `TextBoxFor` is lacking `mode` inside of `@data_options`. – Travis J Aug 29 '13 at 19:21
  • you're correct - sorry, copy paste error - corrected above – Mark Aug 29 '13 at 20:02

2 Answers2

10

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

Vladimir
  • 7,345
  • 4
  • 34
  • 39
3

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

Instead of pasting the answer, check out Stop the tag builder escaping single quotes ASP.NET MVC 2

Also, this isn't quite the same exact question, but then it is. I'll leave it up to others if they want to close it and cite the above reference.

Community
  • 1
  • 1
Brad Christie
  • 100,477
  • 16
  • 156
  • 200