gpt4 book ai didi

css - 如何使用 ASP.NET MVC 引用 CSS 样式?

转载 作者:技术小花猫 更新时间:2023-10-29 11:50:45 29 4
gpt4 key购买 nike

在 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com