views:

32

answers:

1

I am converting an ASP.NET MVC application to ASP.NET MVC 2 4.0, and get this error:

Operator '+' cannot be applied to operands of type 'System.Web.Mvc.MvcHtmlString' and 'System.Web.Mvc.MvcHtmlString'

HTML = Html.InputExtensions.TextBox(helper, name, value, htmlAttributes) 
       + Html.ValidationExtensions.ValidationMessage(helper, name, "*");

How can this be remedied?

+1  A: 

You can't concatenate instances of MvcHtmlString. You will either need to convert them to normal strings (via .ToString()) or do it another way.

You could write an extension method as well, see this answer for an example: http://stackoverflow.com/questions/3460762/how-to-concatenate-several-mvchtmlstring-instances/3464634#3464634

Alastair Pitts
I am new to MVC, here is the code:public static string ExTextBox(this HtmlHelper helper, string name, object value, bool readOnly, object htmlAttributes) { string HTML = ""; //if (readOnly) HTML = String.Format("<label for='{0}'>{1}</label>", name, value); if (readOnly) HTML = value == null ? "" : value.ToString(); else HTML = System.Web.Mvc.Html.InputExtensions.TextBox(helper, name, value, htmlAttributes) + System.Web.Mvc.Html.ValidationExtensions.ValidationMessage(helper, name, "*"); return HTML; }
Thank you so much, it worked
@hnabih: If this is the correct answer, don't forget to mark it as such :)
Alastair Pitts
Thanks, I am new to this site
@hnabih: No problems! Welcome to the SO community :)
Alastair Pitts