[英]How to set Html element class name using data annotation
有没有办法使用数据注释将元素的 class 设置为代码隐藏中提供的值? 例如 - 我希望能够做这样的事情:
public class MyModel
{
[Some annotation to set the html class for this to a custom value such as "MyCustClass"]
public string CustName {get; set;}
}
然后在视图中:
@Html.EditorFor(model => model.CustName)
这将导致绑定到 CustName 的元素 Html class 设置为“MyCustClass”。
我知道可以从 Razor 方法调用中设置 class 名称。 但是我们可能想通过装饰 model 属性来做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.