0

ASP .Net カスタム ルートが機能しない。

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        //default route
        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } // Parameter defaults
        );

       //custom route
        routes.MapRoute(
         "Admin",
         "Admin/{addressID}",// controller name with parameter value only(exclude parameter name)
         new { controller = "Admin", action = "address" }
       new { addressID = @"\d+" }
     );
    }

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }


    public ActionResult address(int addressID = 0)
    {
     //code and redirection
    }

ここで、可能であればURLからすべてを非表示にしたい...可能であればアクション名とパラメーター名と値を非表示にしたい...これを行う可能な方法を提案してください

このような URL が必要です (優先順位に基づいて)
1.http: //localhost:abcd/Admin
または 2.http: //localhost:abcd/Admin/address
または 3.http: //localhost:abcd/Admin/1
または 4.http: //localhost:abcd/Admin/address/1

4

1 に答える 1

1

クイックリファレンス用。

  • カスタム ルートはデフォルトの前に表示されます。
  • カスタム ルートに null という名前を付けてみてください。 routes.MapRoute( null, // Route name...
  • 呼び出しが正しいアクションであることを確認してください。
  • 初期ロード時にパラメーターを受信しないアクション (ページングの例) を扱っている場合は、パラメーターが null 可能 であることaddress(int? addressID) を確認し、カスタム ルートでは次のようにする必要があります。

//custom route
    routes.MapRoute(
     null, //<<--- set to null
     "Admin/{addressID}",// controller name with parameter value only(exclude arameter name)
     new { controller = "Admin", action = "address" }
   //new { addressID = @"\d+" } <<--- no need for this because based from your example " 2.http: //localhost:abcd/Admin/address" the parameter can be null.
 );

ありがとう

于 2013-03-07T10:30:43.300 に答える