改变Html.TextBox的大小 [英] Changing the size of Html.TextBox

查看:169
本文介绍了改变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]属性:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆