I don't like Url.Action("string", "string) and hence wrote below extension method
public static string Action<TController>(this UrlHelper urlHelper, Expression<Func<TController, object>> actionExpression)
{
var controllerName = typeof(TController).GetControllerName();
var actionName = actionExpression.GetActionName();
return urlHelper.Action(actionName, controllerName);
}
I use it in my razor view like below:
@{Url.Action<ClientController>(action => action.ClientDetails());}
It doesn't render anything. Am I making any mistake anywhere or am I missing anything? Is it possible to do this as I like the Type Safe nature, rather than hard-coding actionnames and controllers?