2017-01-01 8 views
1

Я должен попросить о помощи здесь, потому что я больше не знаю, как это происходит и что здесь не так.Пользовательские маршруты переопределяют другие маршруты

Вот маршруты:

 public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "View", 
      url: "{controller}/{action}/{id}/{cid}/{pid}", 
      defaults: new { controller = "Read", action = "R", id = UrlParameter.Optional, cid = UrlParameter.Optional, pid = UrlParameter.Optional } 
     ); 

     routes.MapRoute(
      name: "JsonResult", 
      url: "jsonresult/{id}/{cid}/{pid}", 
      defaults: new { controller = "Find", action = "Readable", id = UrlParameter.Optional, cid = UrlParameter.Optional, pid = UrlParameter.Optional} 
     ); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}", 
      defaults: new { controller = "Read", action = "Index" } 
     ); 
    } 

Там прямо сейчас Serveral проблемы с этим:

Первый - по умолчанию, на дне не работает. По сути, я нахожу маршрут "View", чтобы быть маршрутом . Второй - JsonResult маршрут получает 404 error, и если я поместил его сверху, он исчезнет, ​​но затем View маршрут не работает.

Я действительно не знаю, как исправить, л

ответ

0

Всегда помещайте свой маршрут по умолчанию в верхней части.

Приходит к вашему jsonresult вопросу. Вам не хватает имени контроллера.

public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}", 
      defaults: new { controller = "Read", action = "Index" } 
     ); 

     routes.MapRoute(
      name: "View", 
      url: "{controller}/{action}/{id}/{cid}/{pid}", 
      defaults: new { controller = "Read", action = "R", id = UrlParameter.Optional, cid = UrlParameter.Optional, pid = UrlParameter.Optional } 
     ); 

     routes.MapRoute(
      name: "JsonResult", 
      url: "{controller}/{id}/{cid}/{pid}", /*Changed to Controller here*/ 
      defaults: new { controller = "Find", action = "Readable", id = UrlParameter.Optional, cid = UrlParameter.Optional, pid = UrlParameter.Optional} 
     ); 

    } 
Смежные вопросы