如何在asp.net mvc中创建多行文本框?

Mae*_*024 21 html asp.net-mvc

如何在asp.net mvc中创建多行文本框?

可能不是特定于asp.net mvc,但它是我正在使用的.

这就是我所拥有的.

<%: Html.TextBox("CommentToAdd", null, new
{
@class = "input-medium",    
TextMode = "MultiLine",
Columns = "55",
Rows = "10",
type = "text",
required = "required"
})%>
Run Code Online (Sandbox Code Playgroud)

M.S*_*eri 39

只需将此属性添加到属性即可.

  [DataType(DataType.MultilineText)]
   public string CommentsToAdd{ get; set; }
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用的是EditorFor(),那么DataType.MultilineText可以完成这项工作!很好,谢谢. (4认同)

Dan*_*mms 28

您想要使用文本区域,而不是文本框.使用TextAreaFor将其绑定到模型,否则使用TextArea

<%= Html.TextAreaFor(e => e.CommentsToAdd, 10, 55, null) %>
<%= Html.TextArea("CommentsToAdd", string.Empty, 10, 55, null) %>
Run Code Online (Sandbox Code Playgroud)

使用剃须刀:

@Html.TextAreaFor(e => e.CommentsToAdd, 10, 55, null)
@Html.TextArea("CommentsToAdd", string.Empty, 10, 55, null) 
Run Code Online (Sandbox Code Playgroud)

这将呈现为<textarea>(多行)而不是<input type="text" />(单行).


Sac*_*hin 7

我认为textboxMVC中的多行是textarea

<%= Html.TextArea("Body", null, new { cols = "55", rows = "10" }) %>
Run Code Online (Sandbox Code Playgroud)

要么

<%= Html.TextAreaFor(x => x.Body, 10, 55, null) %>
Run Code Online (Sandbox Code Playgroud)


Tim*_*all 4

多行文本框只是一个文本区域。

其中任何一项都应该有效。

<%= Html.TextArea("Body", null, new { cols = "100", rows = "5" }) %>

<%= Html.TextArea("Body", null, 5, 100, null) %>

<%= Html.TextAreaFor(x => x.Body, 5, 100, null) %>
Run Code Online (Sandbox Code Playgroud)