Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Html.TextArea overload issue

I have a form in an MVC view which contains a number of text boxes, drop down lists and text areas. I am using the HTML helper to create these controls, including pre-populating them with View Data where appropriate, and applying styles via the htmlAttributes parameter.

This is working fine with TextBox controls and DropDownLists etc, however when I add the htmlAttributes to the TextArea it stops working, claiming that the best overloaded method has some invalid arguments, the code that is failing is:

Html.TextArea("Description", ViewData["Description_Current"], new { @class = "DataEntryStd_TextArea" })

The resulting error is:

'System.Web.Mvc.HtmlHelper' does not contain a definition for 'TextArea' and the best extension method overload 'System.Web.Mvc.Html.TextAreaExtensions.TextArea(System.Web.Mvc.HtmlHelper, string, string, object)' has some invalid arguments

For comparison the TextBox calls that are working fine are:

Html.TextBox("TelephoneNumberAlternate", ViewData["TelephoneNumberAlternate"], new { @class = "DataEntryStd_TextBox" })

I tried explicitly referencing the TextAreaExtensions.TextArea and including the HtmlHelper argument however this made no difference.

For info the TextArea call works fine without the htmlAttributes parameter. Additionally I have tried specifying a name/value dictionary for the class attribute however this suffers the exact same problem.

Any ideas what I'm doing wrong?

like image 978
Timbo Avatar asked Dec 08 '22 07:12

Timbo


1 Answers

It always bugs me that these error messages don't tell you which one of the arguments don't match.

Have you tried this?

Html.TextArea("Description", ViewData["Description_Current"].ToString(), new { @class = "DataEntryStd_TextArea" })

The reason I ask is that the ViewData["Description_Current"] is of type Object, and there is an overload with the signature Html.TextArea(String, Object) - although the object in this case represents the html attributes. That could be why the compiler doesn't complain until you add the html attributes as a third parameter - until then, the second parameter is allowed to be an Object, but as soon as you add the third parameter the second has to be a String.

like image 164
Tomas Aschan Avatar answered Dec 17 '22 04:12

Tomas Aschan