示例#1
0
        public override void RegisterArea(AreaRegistrationContext context)
        {
            var defaultUri = UrlProvider <EquipmentController> .GetRouteValues(c => c.Index());

            context.MapRoute(
                "Items_default",
                "Items/{controller}/{action}/{id}",
                new { area = defaultUri["area"], controller = defaultUri["controller"], action = defaultUri["action"], id = UrlParameter.Optional }
                );
        }
示例#2
0
        public static MvcForm BeginForm <TController>(this HtmlHelper htmlHelper, Expression <Action <TController> > expression, object htmlAttributes)
            where TController : Controller
        {
            var urlParts = UrlProvider <TController> .GetRouteValues(expression);

            var controller = urlParts["controller"].ToString();
            var action     = urlParts["action"].ToString();

            return(htmlHelper.BeginForm(action, controller, FormMethod.Post, htmlAttributes));
        }
示例#3
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.MapMvcAttributeRoutes();

            var defaultUri = UrlProvider <EquipmentController> .GetRouteValues(c => c.Index());

            // Register an empty route to fix Area default route registration problems
            var defaultRoute = routes.MapRoute(
                name: Default,
                url: "",
                defaults: new { area = defaultUri["area"], controller = defaultUri["controller"], action = defaultUri["action"], id = UrlParameter.Optional }
                );

            // area data token needs to be set for areas to work properly
            defaultRoute.DataTokens["area"] = defaultUri["area"];

            routes.MapRoute(
                name: Default_NoArea,
                url: "{controller}/{action}/{id}",
                defaults: new { action = defaultUri["action"], id = UrlParameter.Optional }
                );
        }
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            var redirectRoute = UrlProvider <ErrorsController> .GetRouteValues(c => c.UnauthorizedError());

            filterContext.Result = new RedirectToRouteResult(redirectRoute);
        }
示例#5
0
 private static RouteValueDictionary GetRouteValues <TController>(this Expression <Action <TController> > expression)
     where TController : Controller
 {
     return(UrlProvider <TController> .GetRouteValues(expression));
 }