Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC5 textarea rows cols work only when specified explicitly and not via htmlAttributes

@Html.TextAreaFor(model => model.DESCRIPTION, 20, 50, new { htmlAttributes = new { @class = "form-control"} })

Question: The above code displays rows and cols of textarea correctly but the below ignores rows/cols and displays the default size per browser. What's wrong in below code?

The extra new in below code was auto created by VS when creating a MVC Entity Framework controller (as documented at http://www.asp.net/mvc/overview/releases/mvc51-release-notes)

@Html.TextAreaFor(model => model.DESCRIPTION, new { htmlAttributes = new { @class = "form-control", @rows="20", @cols="50"} })

like image 638
joym8 Avatar asked Jan 10 '23 21:01

joym8


2 Answers

This works on MVC 5.2.2:

@Html.TextAreaFor(model => model.Caracteristicas, new { @class = "form-control", @rows = "10" })
like image 92
RolandoCC Avatar answered Jan 18 '23 08:01

RolandoCC


Try using mvc5 cols and rows attribute for TextAreaFor, and also apply the CSS style for the text area.

        <div class="col-md-10" id="textArea">
            @Html.TextAreaFor(model => model.DESCRIPTION, 10, 100, new { htmlAttributes = new { @class = "form-control" } })                
        </div>

And CSS:

#textArea textarea {
max-width: 600px;}
like image 42
Stevan Avatar answered Jan 18 '23 09:01

Stevan