创建使用Html.Helper功能多行文本框 [英] creating multiline textbox using Html.Helper function
本文介绍了创建使用Html.Helper功能多行文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个使用ASP.NET MVC具有以下code多行文本框。
I am trying to create a multiline Textbox using ASP.NET MVC with the following code.
<%= Html.TextBox("Body", null, new { TextBoxMode = "MultiLine", Columns = "55px", Rows = "10px" })%>
这只是表明了一个单行固定大小的文本框。
It just shows up a single line fixed sized textbox.
另一方面
<asp:TextBox runat="server" ID="Body" TextMode="MultiLine" Columns="55" Rows="10"></asp:TextBox>
渲染右视图,但在控制器的POST方法用的FormCollection命名形式
renders the right view, but in the controller's post method with formCollection named form
form["Body"];
返回一个空值。
returns a null value.
推荐答案
在HTML一个多行TextBox是&LT; TextArea&GT;
:
A multiline textbox in html is <textarea>
:
<%= Html.TextArea("Body", null, new { cols = "55", rows = "10" }) %>
或
<%= Html.TextArea("Body", null, 10, 55, null) %>
甚至更好:
<%= Html.TextAreaFor(x => x.Body, 10, 55, null) %>
和另一个可能性是与 [数据类型来装饰您的视图模型属性]
属性:
And yet another possibility is to decorate your view model property with the [DataType]
attribute:
[DataType(DataType.MultilineText)]
public string Body { get; set; }
和在您的视图:
<%= Html.EditorFor(x => x.Body) %>
和设置通过CSS的宽度和高度。
and set the width and height through CSS.
这篇关于创建使用Html.Helper功能多行文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文