You are on page 1of 4

29/5/2019 Asp.

net MVC TextArea - Stack Overflow

Asp.net MVC TextArea Ask Question

How to size the


TextArea and assign
31 Model Value to it in
Asp.net Mvc

asp.net-mvc

3
asked Dec 17 '10 at 9:46
yogee
1,240 4 23 44

4 Answers

Try this:

34 <%=Html.TextAreaFor(
m => m.Descrip
new RouteValue

Edit:
This wont work as far
as I know

<%=Html.TextAreaFor(m

because of this:

private const int Text


private const int Text

// ...

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.
public static str

https://stackoverflow.com/questions/4469277/asp-net-mvc-textarea 1/4
29/5/2019 Asp.net MVC TextArea - Stack Overflow
this H
IDicti
Dictionary
object>();
implicitAt
TextAreaRows.ToString
implicitAt
TextAreaColumns.ToStri
return Tex
value */, implicitAttr

edited Jul 4 '14 at 12:52


KesaVan
880 14 28

answered Dec 17 '10 at 9:50


Aleksei Anufriev
2,673 22 29

For your 1st


example: <%=
Html.TextAreaFor(m
=> m.Description,
15, 20, null) %> –
Simon Bartlett Dec
17 '10 at 9:56

it does't matter add


or remove
dictionary=) I think
question author can
handle this=) –
Aleksei Anufriev
Dec 17 '10 at 10:00

I found a simple away


to achieve this.
24 Using models
annotation razor will
be smart enough to
generate the
By using our site, you acknowledge
textarea . that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.
Model:
https://stackoverflow.com/questions/4469277/asp-net-mvc-textarea 2/4
29/5/2019 Asp.net MVC TextArea - Stack Overflow

[DataType(DataType.Mul
public string Comments

View:

@Html.EditorFor(model

answered Jan 7 '15 at 17:13


meda
40.5k 11 71 113

Assuming you have a


strongly typed view to
9 some model class you
could use the
following:

<%= Html.TextAreaFor(x

or:

<%= Html.TextAreaFor(x

answered Dec 17 '10 at 9:48


Darin Dimitrov
859k 229 3045
2766

For your 2nd


example: <%=
Html.TextAreaFor(x
=> x.SomeProperty,
20, 10, null) %> –
Simon Bartlett Dec
17 '10 at 9:55

Pitfall is
@Html.TextAreaFor

1 because it has no
overload which allow
you assigning a Model
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
Value.
Terms of Service.

https://stackoverflow.com/questions/4469277/asp-net-mvc-textarea 3/4
29/5/2019 Asp.net MVC TextArea - Stack Overflow

Example 1 :

@Html.TextAreaFor(m =
control",@value="Tft.W

Example 1 wont raise


exception and wont
show any text. Let it
down.

Solution :

use @Html.TextArea
instead

Example 2:

@Html.TextArea("Langua
40, new { @class = "fo

Advice :

You should let down


Aspx too because
Razor is lighter and
equivalent syntax.

Just use @ instead of


<%= %>.

edited Mar 17 '14 at 21:20


Johan Falk
4,130 2 25 41

answered Mar 17 '14 at 21:00


Francois Rossello
11 1

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.

https://stackoverflow.com/questions/4469277/asp-net-mvc-textarea 4/4

You might also like