首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在MVC Html.TextBox上应用css类

在MVC中,要在Html.TextBox上应用CSS类,可以使用以下方法:

  1. 使用@Html.TextBoxFor方法生成<input>标签,并使用new { @class = "your-class" }添加CSS类。例如:
代码语言:csharp
复制
@Html.TextBoxFor(model => model.YourProperty, new { @class = "your-class" })
  1. 使用@Html.TextBox方法生成<input>标签,并使用new Dictionary<string, object> { { "class", "your-class" } }添加CSS类。例如:
代码语言:csharp
复制
@Html.TextBox("YourProperty", null, new Dictionary<string, object> { { "class", "your-class" } })

这两种方法都会生成一个包含指定CSS类的<input>标签,例如:

代码语言:html<input type="text" id="YourProperty" name="YourProperty" class="your-class" />
复制

在这个例子中,your-class是你要应用到Html.TextBox的CSS类。你可以在CSS文件中定义这个类的样式,例如:

代码语言:css
复制
.your-class {
    border: 1px solid red;
    background-color: #f0f0f0;
}

这将使得Html.TextBox具有红色边框和浅灰色背景。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券