HTML Helper中的MVC 4属性 [英] MVC 4 Attribute in HTML Helper

查看:75
本文介绍了HTML Helper中的MVC 4属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建此Jquery移动DateBox输入:

I''m trying to create this Jquery mobile DateBox input:

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



我想使用HtmlHelper将DateGroup包含在我的视图模型中,但是它不起作用.这是我尝试过的方法,但不会渲染:



I want to include the DateGroup in my viewmodel, using a HtmlHelper, but it won''t work. This is what I''ve tried, but it wont render:

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


有谁知道如何解决这个问题?

谢谢,
Sunker


Does anyone have an idea of how this can be resolved?

Thanks,
Sunker

推荐答案

尝试以下操作,即可::注意data_role 而不是date-role.

Try the following, it works :) Note data_role instead of date-role.

@Html.TextBoxFor(model => model.Name, new { @data_role = "datebox", @data_options = "'mode':'calbox', 'useNewStyle':true"  })



另外,我尝试了您的方法,带有字典,即使是渲染也是如此.我不确定为什么它不适合您.在两种情况下要注意的一件事是,data-options中的''(单引号)已编码,您可能必须对其进行解码.

您能否详细说明下面的声明?



Also, I tried your way, w/ a dictionary, even that renders. I am not sure why it does not for you. One thing to note in both cases is that the '' (single-quote) in data-options is encoded, which you may have to decode.

Can you elaborate on your statement given below?

I want to include the DateGroup in my viewmodel, using a HtmlHelper, but it won't work


这篇关于HTML Helper中的MVC 4属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆