Cra*_*aig 24 c# editorfor asp.net-mvc-2
我可以在View上设置EditorFor控件的宽度吗?
我设置了一些参数:
[Required, DisplayName("Payee Name"), StringLength(50)]
public string Name { get; set; }
Run Code Online (Sandbox Code Playgroud)
但是,我似乎无法设置渲染的文本框的宽度.
<table width="300" border="0" cellpadding="3" cellspacing="0">
<tr>
<td>
<%=Html.LabelFor(m => m.Name)%>
</td>
<td>
<%=Html.EditorFor(m => m.Name)%>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
这可以以某种方式完成吗?
我试过了:
<%=Html.EditorFor(m => m.Name, new {width=50)%>
Run Code Online (Sandbox Code Playgroud)
但没有快乐......
Mic*_*dox 34
而不是EditorFor,使用TextBoxFor:
<%=Html.TextBoxFor(m => m.Name, new {style = "width:50px"})%>
Run Code Online (Sandbox Code Playgroud)
Eri*_*sch 18
使用CSS设置控件宽度的样式有什么问题?
Pat*_*röm 10
在mvc 5中,site.css中的设置为所有textareas设置max-width = 200.这困惑了我,直到我找到这篇博文. 保罗·利特温(Paul Litwin)说:http://weblogs.asp.net/paullitwin/visual-studio-2013-asp-net-mvc-5-scaffolded-controls-and-bootstrap:
是的,Microsoft出于某种原因将所有输入,选择和textarea控件的最大宽度设置为280像素.不确定这背后的动机,但是在你通过将表单控件分配给其他CSS类来改变它或覆盖它之前,你的控件永远不能超过280px.
/* Set width on the form input elements since they're 100% wide by default */
input,
select,
textarea {
max-width: 280px;
}
Run Code Online (Sandbox Code Playgroud)
所以,如果你是务实的,你可以将最大宽度更改为例如600px
使用引导程序 3
@Html.EditorFor(model => model.PriceIndicatorDesc, new { htmlAttributes = new { @class = "form-control", @style = "width:280px" } })
Run Code Online (Sandbox Code Playgroud)
小智 5
替换<%=Html.EditorFor(m => m.Name, new {width=50)%>为此
<%=Html.EditorFor(m => m.Name,new { htmlAttributes = new { style = "width: 50px" }, }
Run Code Online (Sandbox Code Playgroud)