Add jQuery Mobile transition to ASP.Net MVC Form

2019-08-07 05:44发布

How does one add a jQuery Mobile transition to an HTML POST rendered with the ASP.Net MVC Html.BeginForm helper?

The transition requires an HTML attribute data-transition be added (I think to the form tag, but the docs are unclear on that point, providing only a hyperlink example).

I'm trying to use the BeginForm overload to add attributes to the rendered form tag. When using the new { ... } syntax to declare an anonymous class representing the HTML attributes, I get an error if an attribute name has a dash in it.

using (Html.BeginForm("Login", "Account", FormMethod.Post, 
    new {  data-transition="pop" }))

Error: Invalid anonymous type member declarator

This, in spite of the fact that the MSDN documentation shows an attribute with a dash in the name

new { id = "text1", accept-charset="iso-8859-1" }

2条回答
Deceive 欺骗
2楼-- · 2019-08-07 06:15

Create a dictionary:

using (Html.BeginForm("Login", "Account", FormMethod.Post, 
    new Dictionary<string, object>{{ "data-transition", "pop" }} ))
查看更多
唯我独甜
3楼-- · 2019-08-07 06:16

If you prefer to use an anonymous object to specify your attributes then you could do the following

using (Html.BeginForm("Login", "Account", FormMethod.Post, new { data_transition = "pop" } ))

In short you replace the hypen with an underscore

查看更多
登录 后发表回答