I have converted my classic asp.net mvc views to razor. In a view there is a usage of an extension method (it has overloads) of HtmlHelper:

@Html.CustomAction<AccountController, LogOnModel>("displayText", x => x.Register())

And CustomAction signature is:

public static HtmlString CustomAction<TController, TModel>(this HtmlHelper<TModel> view, string displayText, Expression<Func<TController, object>> where TController : Controller

I have also enabled view compilation at build time (through .proj file). When I build the project I get these errors pointing to that line:

  • Argument 1: cannot convert from 'method group' to 'System.Web.WebPages.HelperResult'

  • The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

What is the reason of these errors? How can I correct it?

share|improve this question
up vote 5 down vote accepted

The Razor parser sees < and thinks it's an HTML tag. Therefore, it only parses Html.CustomAction as the expression.

You need to wrap the call in parentheses to force it to treat the entire call as a single expression:

@(Html.CustomAction<AccountController, LogOnModel>("displayText", x => x.Register()))
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.