TanvirArjel
TanvirArjel

Reputation: 32069

Multiline TextBox/Input Field In ASP.NET Core MVC

To make multi line input field, Like ASP.NET MVC I have tried the following but didn't work in ASP.NET Core MVC:

public class Post
{
   [DataType(DataType.MultilineText)]
   public string Body { get; set; }
}

In the view:

<input asp-for="Body"  rows="40" class="form-control"/>

Any Suggestion will be highly appreciated!!

Upvotes: 21

Views: 29416

Answers (2)

Charles de M.
Charles de M.

Reputation: 693

There is also the option to use the <textarea>-tag

It would look like this:

<div class="form-group">
    <label asp-for="Body">Opmerkingen</label>
    <textarea asp-for="Body" class="form-control" style="text-wrap:normal" type="text" placeholder="Please add your experience here"></textarea>
    <span asp-validation-for="Body" class="text-danger"></span>
</div>

Upvotes: 14

Set
Set

Reputation: 49779

There is an open issue in ASP.NET Core tooling repo.

The suggested workaround is to use

@Html.EditorFor(m => m.Body, additionalViewData: new { htmlAttributes = new { @class = "form-control" }})

or

<textarea asp-for="Body" class="form-control"></textarea>

Upvotes: 27

Related Questions