asp.net-mvc 如何在@Html.TextBox mvc4 中添加新的 css 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16083794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add new css class in @Html.TextBox mvc4
提问by Hemant Soni
I have used following code to add css class with @Html.TextBoxbut this is only working for @Html.TextBoxForand not for @Html.TextBox.
我使用以下代码添加了 css 类,@Html.TextBox但这仅适用@Html.TextBoxFor于@Html.TextBox.
@Html.TextBox("ticket_new_attachment_attributes_0_description", new { @class= "bigfield"})
What am I missing?
我错过了什么?
回答by ssilas777
Try this
尝试这个
@Html.TextBox("ticket_new_attachment_attributes_0_description", null, new { @class= "bigfield"})
回答by Mario Sannum
The second parameter is the value.
You need to use overload with the third parameter for html attributes, like so:
第二个参数是值。
您需要对 html 属性的第三个参数使用重载,如下所示:
// Pass null (or the value) as second parameter
@Html.TextBox("ticket_new_attachment_attributes_0_description", null, new { @class = "bigfield"})
See the msdn reference.
请参阅msdn 参考。
回答by Mario Sannum
For @Html.TextBox second parameter is textbox value so, you can pass "" as textbox value and third parameter is Html attributes
对于@Html.TextBox,第二个参数是文本框值,因此,您可以将 "" 作为文本框值传递,第三个参数是 Html 属性
Try below html :
试试下面的 html :
@Html.TextBox("ticket_new_attachment_attributes_0_description", "", new { @class= "bigfield"})

