2012-05-05 160 views
2

我有一个简单的按钮可视化的问题,这使得完美asp.net的MVC Html.ActionLink忽略jQuery的属性

@Html.ActionLink("<", "Monthly", "Agenda", null, new Dictionary<string, object> { { "data-role", "button" }, { "data-theme", "c" }, { "data-mini", "true" } }) 

我打电话,虽然需要参数的作用,所以我改变了它在

@Html.ActionLink("<", "Monthly", "Agenda", new { shift = -1 }, new Dictionary<string, object> { { "data-role", "button" }, { "data-theme", "c" }, { "data-mini", "true" } }) 

以下这个答案HTML.ActionLink method

当我改变它上面的按钮它的工作,但它并没有呈现为jQuery Mobile的按钮了

从这个http://i47.tinypic.com/alhs9h.png

进入这个http://i48.tinypic.com/351ft5z.png

谢谢你帮我出

回答

5

打到正确Html.ActionLink超负荷你需要通过RouteValues为RouteValueDictionary(不是一个匿名对象):

@Html.ActionLink("<", "Monthly", "Agenda", 
       new RouteValueDictionary() { { "shift", -1 } }, 
       new Dictionary<string, object> { { "data-role", "button" }, { "data-theme", "c" }, { "data-mini", "true" } }) 

或者,更短/更容易阅读,你可以通过的RouteValues和HtmlAttributes为匿名对象:

@Html.ActionLink("<", "Monthly", "Agenda", new { shift = -1 }, new { data_role = "button", data_theme = "c", data_mini = "true" }) 

在匿名对象的版本,你必须使用data_代替data-,但助手代替_-显示属性键,以便前输出是一样的。

+0

感谢@pjumble,为data_指针工作得像个魅力 – gigasean

+0

+1。对于Intellisense而言,感到非常沮丧 – Tommy