/// <summary> /// Register entity controller. /// </summary> /// <param name="type">Type of entity.</param> public void RegisterController(Type type) { if (type == null) { throw new ArgumentNullException("type"); } MvcRouteAttribute route = type.GetCustomAttribute <MvcRouteAttribute>(); if (route == null) { RegisterController(type, type.Name, null); } else { RegisterController(type, route.Controller == null ? type.Name : route.Controller, route.Area); } }
/// <summary> /// Generates a fully qualified URL for the entity. /// </summary> /// <param name="helper">A urlhelper.</param> /// <param name="type">Type of entity.</param> /// <param name="action">Page name.</param> /// <returns></returns> public static string RouteUrl(this UrlHelper helper, Type type, string action) { MvcRouteAttribute route = type.GetCustomAttribute <MvcRouteAttribute>(); if (route == null) { return(helper.RouteUrl(new { controller = type.Name, action = action })); } else if (route.Controller != null) { return(helper.RouteUrl(new { area = route.Area, controller = route.Controller, action = action })); } else { return(helper.RouteUrl(new { area = route.Area, controller = type.Name, action = action })); } }