改变Html.TextBox的大小 [英] Changing the size of Html.TextBox
问题描述
我正在开发使用新的Razor视图引擎的ASP.NET应用程序MVC3但我有一些困难,改变一个文本框,以便它是多行。
到目前为止,所有我已经能够通过谷歌找到的,我需要多行属性设置为true,但我不知道怎么样。
I'm developing an ASP.NET MVC3 application using the new Razor view engine but I'm having some difficulty changing a TextBox so that it is multiline. So far all I've been able to find via google is that I need to set the multiline property to true, but I'm not sure how.
查看code看起来是这样的。
View code looks like this.
<div class="editor-field">
@Html.TextBoxFor(model => model.Body)
</div>
有什么建议?
推荐答案
您可以装饰上的<一个视图模型中的机身
属性href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.aspx\"><$c$c>[DataType]$c$c>属性:
You could decorate the Body
property on your view model with the [DataType]
attribute:
[DataType(DataType.MultilineText)]
public string Body { get; set; }
和在您的视图使用 EditorFor
帮手,而不是 TextBoxFor
and in your view use the EditorFor
helper instead of TextBoxFor
:
<div class="editor-field">
@Html.EditorFor(model => model.Body)
</div>
另一种可能性是离开模型是不添加任何属性,并在视图使用 TextAreaFor
帮手:
<div class="editor-field">
@Html.TextAreaFor(x => x.Body)
</div>
我个人preFER第一种方法。
Personally I prefer the first approach.
这篇关于改变Html.TextBox的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!