我正在做一个使用C#的MVC项目。现在,我正在尝试自定义我的视图,并且我想让文本框更大一些。
我按照这个问题中的建议将单行文本字段转换为多行文本字段:Changing the size of Html.TextBox
现在我正在尝试调整多行字段的大小,但我不确定在哪里或如何做到这一点。
以下是我的编辑视图中的代码片段
<div class="editor-label">
@Html.LabelFor(model => model.Body)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Body)
@Html.ValidationMessageFor(model => model.Body)
</div>
在我的模型中:
[DataType(DataType.MultilineText)]
[DisplayName("Body:")]
public string Body { get; set; }
发布于 2011-02-25 23:44:42
我会用CSS做到这一点:
<div class="editor-multiline-field">
@Html.EditorFor(model => model.Body)
@Html.ValidationMessageFor(model => model.Body)
</div>
然后在CSS文件中将宽度和高度定义为所需的值:
.editor-multiline-field textarea {
width: 300px;
height: 200px;
}
发布于 2012-04-13 17:51:01
您也可以使用@Html.TextArea ou TextAreaFor
@Html.TextAreaFor(model => model.Text, new { cols = 25, @rows = 5 })
发布于 2015-07-31 19:45:05
在MVC5中,您可以使用
@Html.TextAreaFor(model => model.body, 5, 50, new { @class = "form-control" } )
效果很好!
https://stackoverflow.com/questions/5119221
复制相似问题