Domanda

When I use TextAreaFor helper in MVC and I define rows like this:

@Html.TextAreaFor(model => model.Notes, 5)

The number of rows on this text area is not set meaning the size of the text area is not affected at all. However if I use htmlAttributes to define the rows:

@Html.TextAreaFor(model => model.Notes, new { rows = 5 })

then it works fine. So my question is what is the rows property in TextAreaFor helper used for if not to define the rows HTML attribute of the textarea? What am I missing here?

È stato utile?

Soluzione

There is no such overload like your first example. You may try this overload

public static MvcHtmlString TextAreaFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    int rows,
    int columns,
    Object htmlAttributes
)

So your example should be like this

@Html.TextAreaFor(model => model.Notes,5,10, new { @class= "myCssClassName" })

For your second example, you are using the overload in the correct way.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top