添加CSS类Html.TextBox [英] adding a css class with Html.TextBox

查看:139
本文介绍了添加CSS类Html.TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试添加一个类HTML属性,但我认为关键字类导致的问题。

Trying to add a 'class' html attribute, but I think the keyword 'class' is causing issues.

<%: Html.TextBox("name", "value", new {class: " required "})%>

有没有解决办法?

Is there a workaround?

推荐答案

只需preFIX类与@,因为它是一个的保留关键字

Just prefix 'class' with an '@' as it's a reserved keyword.

<%: Html.TextBox("name", "value", new { @class: " required "})%>

如果您需要在@关键字的背景,<一个href=\"http://stackoverflow.com/questions/429529/what-does-the-symbol-before-a-variable-name-mean-in-c\">this是一个很好的SO质疑阅读。

If you need some background on the @ keyword, this is a good SO question to read.

这篇关于添加CSS类Html.TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆