Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling an HTML.TextAreaFor in MVC3

I have a C#.Net MVC3 web app and we use HTML.TextAreaFor() text areas for editting and display. In one instance it should be edittable and in another it shuold be display only. How would I accomplish this? Is there another element I should use or can I make the TextAreaFor disabled? Also, the TextAreaFor needs to word wrap in the display only mode as well...it's in a grid cell

like image 727
MikeTWebb Avatar asked Nov 14 '11 23:11

MikeTWebb


1 Answers

Just use the htmlAttributes parameter:

@Html.TextAreaFor(model => model.Something, new { @readonly = true })

To tidy up the if / else in your View, use an extension method which does the if check and renders out the different textbox.

Not sure what you mean about word wrapping - from my understanding <textarea> elements always wrap, unless you use wrap="off"

like image 135
RPM1984 Avatar answered Sep 18 '22 17:09

RPM1984