Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Html.EditorFor to generate a textarea with a specific number of rows and columns

I know you can use the DataType attribute with the EditorFor html helper to specify that a particular property of a model entity should be displayed as a multi-line input field.

What If I want to specify the number of rows and columns the text area must have?

In the model :

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

In the view :

@Html.EditorFor(x => x.HTMLText)

Wanted result :

<textarea id="HTMLText" rows="10" cols="40">value</textarea>

Is there a way to generate this kind of code without using the @Html.Textarea() helper?

like image 945
Jason Avatar asked Feb 10 '11 03:02

Jason


2 Answers

Not sure how to set the rows and cols, but you can alter the CSS of those textareas using the .multi-line class. This class is added to the textarea when using EditorFor so you can specify the width and height in that class to get your desired dimensions.

.multi-line { height:5em; width:5em; }
like image 127
amurra Avatar answered Oct 18 '22 19:10

amurra


You can specify the attributes size and char equivalent of row and col in Razor/c# ie:

@Html.TextAreaFor(model => model.Longtext, new { htmlAttributes = new { @class = "ctrl-col2 ctrl-col1", @row = "4", @col = "30" } })
like image 44
Lmrini Frozen Avatar answered Oct 18 '22 18:10

Lmrini Frozen