ProgrammerGuide.Net | Step by Step Programmer Guide

Rendering Textarea Using @Html.EditorFor | ASP.NET MVC

The default view generated will render an input control of type text for a string field.

@Html.EditorFor(model => model.Text)

However, if you want to have a textarea for the string field to facilitate the user to provide multiline text, we need to use [DataType] attribute on your view model

public class MyViewModel
{
    [DataType(DataType.MultilineText)]
    public string Text { get; set; }
}

Don’t forget to import System.ComponentModel.DataAnnotations as below

using System.ComponentModel.DataAnnotations;

Now, your view will render a textarea for the string field.

Please click here for related products on Amazon!

Jayashee

Add comment

Want to Check Celebrities News?