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

Asp.net mvc 如何在MVC Html.TextBox上应用css类,asp.net-mvc,css,Asp.net Mvc,Css,我的MVC应用程序中有以下标记。如何将类应用于文本框 <%= Html.TextBox("username", "", new { maxlength = 50 })%> 假设输入框的类名为“username”,则使用: input[type=text].username { /* styles here */ } 根据您的代码,我相信Html.TextBox helper方法也会从name字段自动创建一个id: id="username" 然后,您可以通过以下CSS访问文

我的MVC应用程序中有以下标记。如何将类应用于文本框

<%= Html.TextBox("username", "", new { maxlength = 50 })%>

假设输入框的类名为“username”,则使用:

input[type=text].username {
  /* styles here */
}

根据您的代码,我相信Html.TextBox helper方法也会从name字段自动创建一个id:

id="username"
然后,您可以通过以下CSS访问文本框:

#username {
    /* styles */
}

你有一个看似正确的答案——接受它?
id="username"
#username {
    /* styles */
}