如何自定义数据属性和类添加到`@ Html.EditorFor`? [英] How to add custom data attributes and classes to `@Html.EditorFor`?

查看:152
本文介绍了如何自定义数据属性和类添加到`@ Html.EditorFor`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一些自定义属性被 @ Html.EditorFor 生成的输入,我尝试以下

I want to add some custom attributes to the input generated by @Html.EditorFor, I tried the following:

@Html.EditorFor(model => model.Percent, new { @class = "percent" })

但它只是忽略了我的课,从我可以从身边寻找告诉是模板不支持添加自定义属性。

But it just ignores my class, from what I can tell from searching around is that the template doesn't support adding custom attributes.

但是,我们如何创建自定义模板添加了自定义属性的支持,同时保持旧模板的所有功能?

But how does one create a custom template adding support for the custom attributes, while keeping all the functionality of the old template?

推荐答案

请参阅下面的帖子,这个问题已经被#2问。

Please see the following posts, this question has been asked before on Stackoverflow.

  • Add css class to Html.EditorFor in MVC 2
  • Set the class attribute to Html.EditorFor in ASP.NET MVC Razor View
  • Asp.net MVC 3 Razor - Adding class to EditorFor

有更多的例子,只是谷歌了。

There are many more examples, just Google it.

我希望这有助于。

这篇关于如何自定义数据属性和类添加到`@ Html.EditorFor`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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