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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16026892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:34:52  来源:igfitidea点击:

How do I create a multi line text box in asp.net mvc?

htmlasp.net-mvc

提问by Maestro1024

How do I create a multi line text box in asp.net mvc?

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

Probably not specific to asp.net mvc but it is what I am using.

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

Here is what I have.

这是我所拥有的。

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

回答by M.Shakeri

just add this attribute to property.

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

  [DataType(DataType.MultilineText)]
   public string CommentsToAdd{ get; set; }

回答by Daniel Imms

You want to use a text area, not a text box. Use TextAreaForto bind it to your model, otherwise use TextArea

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

<%= Html.TextAreaFor(e => e.CommentsToAdd, 10, 55, null) %>
<%= Html.TextArea("CommentsToAdd", string.Empty, 10, 55, null) %>

Using razor:

使用剃须刀:

@Html.TextAreaFor(e => e.CommentsToAdd, 10, 55, null)
@Html.TextArea("CommentsToAdd", string.Empty, 10, 55, null) 

This will be rendered as a <textarea>(multi-line) instead of an <input type="text" />(single line).

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

回答by Sachin

I think multiline textboxin MVC is textarea

我认为textboxMVC 中的多行是textarea

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

or

或者

<%= Html.TextAreaFor(x => x.Body, 10, 55, null) %>

回答by Timothy Randall

A multiline textbox is just a textarea.

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

Any one of these should work.

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

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

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

<%= Html.TextAreaFor(x => x.Body, 5, 100, null) %>