Sha*_*ean 237 asp.net-mvc html5 asp.net-mvc-3
如何data-*使用TextboxFor 添加html属性?
这就是我目前拥有的:
@Html.TextBoxFor(model => model.Country.CountryName, new { data-url= Url.Action("CountryContains", "Geo") })
Run Code Online (Sandbox Code Playgroud)
如你所见,这-引起了一个问题data-url.这是怎么回事?
Dar*_*rov 409
你可以使用下划线(_),帮助器足够聪明,可以完成剩下的工作:
@Html.TextBoxFor(
model => model.Country.CountryName,
new { data_url = Url.Action("CountryContains", "Geo") }
)
Run Code Online (Sandbox Code Playgroud)
对于那些希望在ASP.NET MVC 3之前版本中实现相同功能的用户,他们可以:
<%= Html.TextBoxFor(
model => model.Country.CountryName,
new Dictionary<string, object> {
{ "data-url", Url.Action("CountryContains", "Geo") }
}
) %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
71746 次 |
| 最近记录: |