Marek Marek - 1 year ago 91
HTML Question

How to make multi line in textbox MVC?

How to make multi line in textbox MVC. In web forms I could change it in HTML:


but how to do this in MVC textbox?

@Html.TextBox("Napisz", null, new { @class = "ostatni" })

enter image description here

Answer Source

You can use the TextArea helper method

@Html.TextArea("Napisz", null, new { @class = "ostatni" })

This will render a textarea, not an input text element with multi line support.

If you want to specify the custom row number and column number, you can specify that in the htmlAttributes parameter

@Html.TextArea("Napisz", null, new { @class = "ostatni", rows=5, cols="30" })

Another thing to note is, It is not necessary to use these helper methods. These methods simply generate the htmk markup. So instead of using these helper methods, you are free to write pure markup like this

<textarea class="ostatni" cols="30" id="Napisz" name="Napisz" rows="5"></textarea>

In core, we have tag helpers and usage of which is very similar to writing pure html (it was created for the front end designers who does not need to worry about c#)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download