我如何编辑Html.DisplayFor方法的CSS在MVC 3? [英] How do I edit the CSS of the Html.DisplayFor method in MVC 3?

查看:193
本文介绍了我如何编辑Html.DisplayFor方法的CSS在MVC 3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的code,显示在我看来,从我的观点示范文本:

  @ Html.DisplayFor(M => m.Name)
 

当我看看IE9的HTML细节(这是我在工作中使用),没有与这个名字相关联的类,它只是使用了车身CSS样式,而不是显示字段级的造型。有谁知道什么可能会造成这个问题或如何我会编辑CSS文本产生的?

解决方案

DisplayFor用于模板的原因

。如果不使用模板,那么你应该使用像这样的项目: @ Model.Name 如果你想给它一个类或ID,那么你需要包裹在一个跨度或股利。

您的问题是,你使用了错误的方法来输出数据,并期待它做些别的事情。没有内置的方式来输出原始数据与类名。

所以,你的选择是,在包装容器的原始项目,你可以将CSS应用到,或创建一个模板使用这些,那么在DisplayFor像这样指定模板名称:

  @ Html.DisplayFor(M => m.Name,NameTemplate)
 

I am using the following code to display text from my view model in my view:

@Html.DisplayFor(m => m.Name)

When I look at the HTML details in IE9 (which I have to use at work) there is no class associated with the name, it just uses the Body CSS styling instead of the display-field class styling. Does anyone know what might be causing this issue or how I might edit the CSS for the text created?

解决方案

DisplayFor is used for templating reasons. If you aren't using a template, then you should just use the item like so: @Model.Name If you want to give it a class or id, then you need to wrap it in a span or div.

Your problem is that you're using the wrong method to output data, and expecting it to do something else. There is no built-in way to output raw data with class names.

So your choices are, wrap the raw item in a container that you can apply the css to, or create a template to use for these, then specify the template name in the DisplayFor like so:

 @Html.DisplayFor(m => m.Name, "NameTemplate")

这篇关于我如何编辑Html.DisplayFor方法的CSS在MVC 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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