如何在输入Html.TextBox时包装文本

时间:2011-01-26 18:46:28

标签: asp.net-mvc-2

下面的标记就是我现在所拥有的。我正在写一个MVC应用程序。 我发现这个网站上的建议导致我插入宽度和高度,但这并没有解决我的问题。 当我输入的文本长度超过500px时我想要它换行,目前它全部停留在一行上,显然,完整的文本是不可见的。 有人可以帮忙吗?

感谢

                           描述你的特价:                          
            
            <%= Html.TextBox(“ShortDescription”,Model.Special.ShortDescription,new {@ style =“width:500px; height:60px; background-color:#f1f2f3”})%>

2 个答案:

答案 0 :(得分:4)

Html.TextBox助手生成<input type="text" ...,此类输入中的文本不会换行。您应该考虑使用<textarea>。您可以使用Html.TextAreaFor帮助程序(不是Html.TextArea,因为您已经拥有模型,因此可以从中获利):

<%= Html.TextAreaFor(x => x.Special.ShortDescription, 10, 20, 
    new { @style = "background-color: #f1f2f3" }) %>

答案 1 :(得分:0)

您应该可以使用TextArea:

<%= Html.TextArea("ShortDescription", Model.Special.ShortDescription) %> 

或明确说明您的情况:

<%= Html.TextArea("ShortDescription", Model.Special.ShortDescription, 
    new { @style = "width: 500px; height:60px;background-color:#f1f2f3" })%>