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?
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: How to concatenate several MvcHtmlString instances
Personally I use a very slim utility method, that takes advantage of the existing Concat() method in the string class:
public static MvcHtmlString Concat(params object[] args)
{
return new MvcHtmlString(string.Concat(args));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With