Unable to call generic Url.Action<TController> method from View

623 views Asked by At

I'm using ASP.NET MVC 3, along with MvcContrib v 3. MvcContrib has a UrlHelper extension that I'm trying to use in my view. The extension code is as follows:

public static class UrlHelperExtensions
{
    public static string Action<TController>(this UrlHelper urlHelper, Expression<Action<TController>> expression)
    where TController : Controller
    {
        return LinkBuilder.BuildUrlFromExpression<TController>(urlHelper.RequestContext, urlHelper.RouteCollection, expression);
    }
}

However, ASP.NET MVC does not appear to like any syntax I try when using the method in my View.

enter image description here

1

There are 1 answers

0
Andre Pena On BEST ANSWER

Surround it with a @(). You can't use generics in Razor outside a @() block. It would be like:

@(Url.Action<TController>(c => c.YourAction())