css类添加到Html.EditorFor在MVC 2 [英] Add css class to Html.EditorFor in MVC 2

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

问题描述

我想一个CSS类添加到一个文本框。这是我在我的观点:

I'm trying to add a css class to a textbox. This is what I have in my view:

<%: Html.EditorFor(m => m.StartDate) %>

我试过下面通过这个链接指示我code:

<%: Html.EditorFor(m => m.StartDate, new { @class: "datepicker" }) %>

不过,我得到一个编译错误说:

But I get a compiler error saying:

语法错误,,预期

我在做什么错在这里?

推荐答案

我会强烈建议使用<一个href=\"http://geekswithblogs.net/michelotti/archive/2010/02/05/mvc-2-editor-template-with-datetime.aspx\">Editor模板。这绝对是正确的方式风格你EditorFor。

I would HIGHLY suggest using Editor Templates. It's definitely the "right" way to style your EditorFor.

您可以告诉一个模型属性两种不同的方式来使用编辑器模板。

You can tell a model property to use an Editor Template in two different ways.

第一个(最简单的)是创建一个特定的数据类型编辑模板 - 的DateTime 例如结果
做到这一点的第二种方法是使用 UIHint

The first (the simplest) is to create an editor template for a certain data type - DateTime for example.
The second way to do it is to set it declaratively in your DataAnnotations by using a UIHint.

修改结果
我还想补充一点,你应该在你的输入字段中使用日期类型,这样即使在JavaScript被禁用,您的用户可以看到剧照土生土长的日期选择器(仅适用于现代的HTML5浏览器有效)结果
&LT;输入ID =开会类型=日期值=2011-01-13/&GT;

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

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