如何将样式应用于asp.net mvc @ Html.TextboxFor?
我想更改文本框的背景。 这是我的代码:
@Html.TextBoxFor(p => p.Publishers[0].pub_name)
我还需要在TextBoxFor中编写更改背景的内容吗?
TextBoxFor方法的重载允许您传递HTML属性的对象。
@Html.TextBoxFor(p => p.Publishers[0].pub_name, new { Class="YourBackgroundClass" })
然后你可以有一个CSS规则,如:
.YourBackgroundClass { background:#cccccc; }
如果您想直接应用样式,您可以:
@Html.TextBoxFor(p => p.Publishers[0].pub_name, new { Style="background:#cccccc;" })
在我的情况下,我确实喜欢下面。 我有ASP.NET MVC应用程序,我们正在使用Bootstrap。 我给了浮动:留给我所有的div元素。 只是想展示如何将@style与@class一起用于@ Html.TextBoxFor
@Html.TextBoxFor(m => Model.UserPrincipalName, new { @id = "LoginName", @class = "form-control", @style = "float:left;margin-right:10px;margin-top:-5px;" }) @Html.Raw(" Search ")
现在你可以像这样添加html属性:
@Html.EditorFor(p => p.Publishers[0].pub_name, new { htmlAttributes = new { @class = "YourBackgroundClass" } })