5 Replies - 6825 Views - Last Post: 10 September 2012 - 12:12 PM

#1 sunkerman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-September 12

MVC 4 Attribute in HTML Helper

Posted 10 September 2012 - 09:15 AM

Hi,

I want to render this:
<input name="mode1" id="mode1" type="text" data-role="datebox" data-options='{"mode":"calbox", "useNewStyle":true}' />


...using a HtmlHelper. This is what I've tried, but it won't render:

@Html.TextBoxFor(model => model.Date,
                       new Dictionary<string, object> {
                                                          { "data-role", "datebox" },
                                                          { "data-options", "'mode':'calbox', 'useNewStyle':true" },
                                                      })


Anyone knows how this can be solved?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: MVC 4 Attribute in HTML Helper

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3617
  • View blog
  • Posts: 11,269
  • Joined: 05-May 12

Re: MVC 4 Attribute in HTML Helper

Posted 10 September 2012 - 10:18 AM

If you comment out line 4, does it render?
Was This Post Helpful? 0
  • +
  • -

#3 sunkerman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-September 12

Re: MVC 4 Attribute in HTML Helper

Posted 10 September 2012 - 10:42 AM

If I remove this? { "data-options", "'mode':'calbox', 'useNewStyle':true" }

No it won't, or the input will render, but the jq mobile plugin won't work then. When using the calendar picker, I get this error: "There is no mode by that name loaded/mode not given", so the mode:calbox is needed. By the way, this is the plugin I'm using. http://dev.jtsage.com/jQM-DateBox/

Thanks for the reply
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3617
  • View blog
  • Posts: 11,269
  • Joined: 05-May 12

Re: MVC 4 Attribute in HTML Helper

Posted 10 September 2012 - 10:48 AM

Okay, so it does render. It's just that the plugin doesn't work.

So when uncomment line 4, does it still render?

And if it does render, then I have a question. What happened to the curly braces? In your expected output you have:
{"mode":"calbox", "useNewStyle":true}


Yet in your dictionary, you have:
'mode':'calbox', 'useNewStyle':true


Was This Post Helpful? 0
  • +
  • -

#5 sunkerman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-September 12

Re: MVC 4 Attribute in HTML Helper

Posted 10 September 2012 - 11:15 AM

Yes, it renders. Sorry, I've tried both "{'mode':'calbox', 'useNewStyle':true}" and "'mode':'calbox', 'useNewStyle':true" in the dictionary but neither works.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3617
  • View blog
  • Posts: 11,269
  • Joined: 05-May 12

Re: MVC 4 Attribute in HTML Helper

Posted 10 September 2012 - 12:12 PM

It doesn't work as in it doesn't render, or as in the plugin doesn't seem to understand the single quotes?

Actually, it kind of makes sense, if it renders, but the plugin doesn't understand. JSON definition for a string is double quotes, not single quotes. http://www.json.org/

Have you tried:
"{\"mode\":\"calbox\", \"useNewStyle\":true}"



Or
"{&quot;mode&quot;:&quot;calbox&quot;, &quot;useNewStyle&quot;:true}"


This post has been edited by Skydiver: 10 September 2012 - 12:18 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1