我想改变文本框的背景。这是我的代码:
@Html.TextBoxFor(p => p.Publishers[0].pub_name)
在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元素设置了float:left。 只是想展示如何在@Html.TextBoxFor中同时使用@style和@class
<div class="modal-body" style="height:auto; overflow-y:auto;max-height:500px;">
<table style="width:100%" cellpadding="10">
<tr>
<td>
<div style="display: inline; ">
<label style=" float:left; margin-right:20px;">Login Name: </label>
@Html.TextBoxFor(m => Model.UserPrincipalName, new { @id = "LoginName", @class = "form-control", @style = "float:left;margin-right:10px;margin-top:-5px;" })
<a href="#" onclick="SearchActiveDirectoryByLoginName()" title="Search Active Directory" class="btn btn-primary" style="float: left; margin-top: -5px;">
@Html.Raw(" Search ")
</a>
</div>
</td>
</tr>
</table>
</div>
@Html.EditorFor(p => p.Publishers[0].pub_name, new { htmlAttributes = new { @class =
"YourBackgroundClass" } })
@Html.TextBoxFor(p => p.Publishers[0].pub_name, new { foreground = "red" })
。 - TCM@class
,因为class
是保留关键字。 - Dan Abramov