Disabling HTML.TextAreaFor in MVC3

I have a C # .Net MVC3 web application, and we use HTML.TextAreaFor () text areas for editing and display. In one case, it should be editable, and in the other it should be displayed only. How would I do that? Is there another element that I should use, or can I disable TextAreaFor? In addition, TextAreaFor you need to wrap words in display mode only ... in the grid cell

+6
source share
2 answers

Just use the htmlAttributes parameter:

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

To remove if / else in your view, use an extension method that performs an if check and displays a different text field.

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

+20
source

In the second part of your question, you can disable the wrapper as follows:

  @Html.TextAreaFor(m => m.Name, new { wrap = "off" }) 
+1
source

Source: https://habr.com/ru/post/901471/


All Articles