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?
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()))
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