在 ASP.NET MVC 中,我可以像这样定义一个文本框编辑器并为其指定样式。
@Html.TextBoxFor(m => m.Notes[i].Notes, new { style = "width: 500px;" });
如何将样式移动到 Site.css 文件并仅从上面的代码中引用它?
.myStyle {
width: 500px;
}
我试过这个编译但似乎不起作用:
@Html.TextBoxFor(m => m.Notes[i].Notes, "myStyle");
最佳答案
你想给它一个 class
属性来匹配你的 CSS 规则:
@Html.TextBoxFor(m => m.Notes[i].Notes, new { @class = "myStyle" });
请注意,@class
中的@
在ASP.NET MVC 中没有特殊含义。它只是将 C# 中的关键字 class
转换为标识符,因此您可以将其作为属性传入并进行编译。
关于css - 如何使用 ASP.NET MVC 引用 CSS 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9884395/