4

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?

1 Answer 1

8

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()))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.