繁体   English   中英

使用Html.TextBoxFor时如何设置文本框的宽度

[英]How to set the width of the text box when using Html.TextBoxFor

我认为我有以下几行:

<div class="editor-field">
     <%= Html.TextBoxFor(m => m.Description)%>                    
</div>

如何定义文本框的宽度?

这对我来说是一次性的,但是非常冗长:

<%: Html.TextBoxFor(m => m.Description, new { style="width:50px;" })%>

可重用的解决方案是在css文件中设置宽度

.wide
{
     width: 300px;
}

然后使用上面的标记设置它

<%= Html.TextBoxFor(m => m.Description, new { @class= "wide" })%> 

您可以将其作为属性附加。 尝试这个:

<div class="editor-field">
     <%= Html.TextBoxFor(m => m.Description, new { style = "width:20em;" })%>                     
</div>

你也可以这样做

  @Html.TextBoxFor(model => model.Email, new Dictionary<string, object>() { { "readonly", "true" }, { "style", "width:250px;" } })

对我来说,它通过在CSS中为@Html.TextBoxFor添加“输入”来实现:

CSS:

.campoTexto input {
    width: 50px;
}

对于:

<div class="campoTexto">
@Html.TextBoxFor(model => model.nombre)
</div>

只需使用像“TextBoxFor,TextArea”等属性而不是“EditorFor”...很多人在使用脚手架时,他们必须自己更改字段或像[DataType(Multiline)]这样的模型中的数据注释

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM