How to Increase the size of TextArea in html razor view mvc4?
Asked Answered
Y

8

8

I have one text area field called Description in my view. I wish to increase the size of that field.

My code

  <div class="col-sm-3">
  <div class="form-group">
  <span style="color: #f00">*</span>
   @Html.LabelFor(model => model.Description, new { @class = "control-label" })
   @Html.TextAreaFor(model => model.Description, new { @class = "required", style = " rows=10, columns=40" })
   @Html.ValidationMessageFor(model => model.Description)
       </div>
     </div>

My TextArea

TextArea

I want to bring as like which is mention in the below image

Wanted Output

So i gave Rows and columns in textarea field. It increase the size of the text area. But when i shrink the page to phone size means all fields got shrink . But this textarea field is not shrink up to the page size. This is the issue

I kept validation for my fields. I want to show that validation in Red color. I'm using Model validation.

Yeh answered 3/5, 2016 at 4:11 Comment(0)
A
18

Try This:

  @Html.TextAreaFor(model => model.Description, 10,40, htmlAttributes: new {style="width: 100%; max-width: 100%;" })
Antitrades answered 3/5, 2016 at 4:24 Comment(0)
F
14

While this is already answered, Someone out there might still need this.

 @Html.TextAreaFor(model => model.comments, 
 new { @cols = "100", @rows =  "8", @style="width:100%;"})
Fermentative answered 10/11, 2017 at 23:15 Comment(1)
That person is me. Appreciate it!Ternion
S
0

Rows and Cols does not come under style tag. Its an independent attribute for textarea. You can write it as below.

@Html.TextAreaFor(model => model.Description, new { @class = "required", @cols = 40, @rows = 10})
Samhita answered 3/5, 2016 at 4:17 Comment(0)
D
0
Remove textArea element from site.css file. In site.css textarea max-width set as 280px;
Do like

input
,select
/*,textarea*/ 
{
    max-width: 280px;
}
Demonology answered 22/12, 2016 at 10:12 Comment(0)
D
0

use this MVC razor syntax will take only value @Html.TextAreaFor(model => model.comment, 10, 40, new { htmlAttributes = new { @class = "form-control" } });

Denna answered 8/3, 2023 at 19:32 Comment(0)
T
-1
@Html.TextAreaFor(m => m.Description, 10, 40, new { @class = "form-control required", style="max-width:75% !important;" })
Th answered 18/10, 2017 at 19:3 Comment(0)
L
-1
  @Html.TextAreaFor(model => model.Description, new { @class = "form-control", @cols = 10, @rows = 10,@style="resize:both;" })
Lemmons answered 19/12, 2019 at 12:38 Comment(1)
Explain your answer.Atronna
A
-1

@Html.TextAreaFor(model => model.Description,10,40, new { @class = "required"})

Absorbance answered 19/6, 2020 at 7:18 Comment(1)
Please share some info around why your answer works instead of just pasting code.Elissaelita

© 2022 - 2024 — McMap. All rights reserved.