在MVC中,要在Html.TextBox上应用CSS类,可以使用以下方法:
@Html.TextBoxFor
方法生成<input>
标签,并使用new { @class = "your-class" }
添加CSS类。例如:@Html.TextBoxFor(model => model.YourProperty, new { @class = "your-class" })
@Html.TextBox
方法生成<input>
标签,并使用new Dictionary<string, object> { { "class", "your-class" } }
添加CSS类。例如:@Html.TextBox("YourProperty", null, new Dictionary<string, object> { { "class", "your-class" } })
这两种方法都会生成一个包含指定CSS类的<input>
标签,例如:
在这个例子中,your-class
是你要应用到Html.TextBox
的CSS类。你可以在CSS文件中定义这个类的样式,例如:
.your-class {
border: 1px solid red;
background-color: #f0f0f0;
}
这将使得Html.TextBox
具有红色边框和浅灰色背景。
第五届Techo TVP开发者峰会
云+社区技术沙龙[第1期]
高校公开课
腾讯位置服务技术沙龙
云+未来峰会
云+社区技术沙龙[第9期]
第四期Techo TVP开发者峰会
云+社区开发者大会(苏州站)
领取专属 10元无门槛券
手把手带您无忧上云