ASP.NET MVC 3 Razor - 向 EditorFor 添加类 [英] ASP.NET MVC 3 Razor - Adding class to EditorFor

查看:31
本文介绍了ASP.NET MVC 3 Razor - 向 EditorFor 添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向输入添加一个类.

这不起作用:

@Html.EditorFor(x => x.Created, new { @class = "date" })

解决方案

Html.EditorFor 添加一个类没有意义,因为在它的模板中你可以有许多不同的标签.所以你需要在编辑器模板里面分配类:

@Html.EditorFor(x => x.Created)

在自定义模板中:

@Html.TextBoxForModel(x => x.Created, new { @class = "date" })

I'm trying to add a class to an input.

This is not working:

@Html.EditorFor(x => x.Created, new { @class = "date" })

解决方案

Adding a class to Html.EditorFor doesn't make sense as inside its template you could have many different tags. So you need to assign the class inside the editor template:

@Html.EditorFor(x => x.Created)

and in the custom template:

<div>
    @Html.TextBoxForModel(x => x.Created, new { @class = "date" })
</div>

这篇关于ASP.NET MVC 3 Razor - 向 EditorFor 添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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