English 中文(简体)
ASP.NET MVC 3
原标题:Handling Routes in ASP.NET MVC 3

我正试图为“区域”铺设我的道路,我有以下需要允许的URLs:

  1. http://localhost/Review/Setup
  2. http://localhost/Review/Setup/65
  3. http://localhost/Review/Setup/_AjaxGetMember?ReviewId=53

Area = Review | Controller = Setup | Action = Index

因此,对于《欧洲经济、社会、文化权利国际公约》,它们应当:

  1. http://localhost/Review/Setup/Index
  2. http://localhost/Review/Setup/Index/65
  3. http://localhost/Review/Setup/_AjaxGetMember?ReviewId=53

这里是该地区目前登记的路线。

context.MapRoute(
    "Review_default",
    "Review/{controller}/{action}/{id}",
    new
    {
        action = "Index",
        id = UrlParameter.Optional
    }
);

现在,在我的第一份清单工作中,有1和3份,但2份没有将索引列入《欧洲刑法》。 我可以补充的是,这些URLs的工作使得不必在URL中添加或显示指数?

谢谢。

最佳回答

处理。 我需要增加更多的路线。 这样做可能更可取,但我只是经过测试,而且工作。

context.MapRoute(
    "Review_default",
    "Review/{controller}/{id}",
    new
    {
        action = "Index",
        id = UrlParameter.Optional
    },
    new
    {
        id = @"d*"
    }
);


context.MapRoute(
    "Review_default2",
    "Review/{controller}/{action}/{id}",
    new
    {
        action = "Index",
        id = UrlParameter.Optional
    },
    new
    {
        action = @"[A-Za-z]+",
        id = @"d*"
    }
);

context.MapRoute(
    "Review_default3",
    "Review/{controller}/{action}/{id}",
    new
    {
        action = "Index",
        id = UrlParameter.Optional
    },
    new
    {
        action = @"_[A-Za-z]+",
        id = @"d*"
    }
);
问题回答

我没有对此进行测试,而是我如何尝试:

context.MapRoute(
    "Review_setup_directId",
    "Review/Setup/{id}",
    new
    {
        controller = "Setup",
        action = "Index",
        id = UrlParameter.Optional
    }
);




相关问题
Rails: Proxy Pass?

I ve got a web-app that I want to migrate to Rails, which is currently just plain HTML with an Apache proxy to another server, running a custom database/webserver that serves the site s dynamic ...

MVC routing is not handling one of my directories

I m using ASP.NET MVC with IIS 7.0. I ve got 404 errors hooked up fine through my Application_Error override. In addition to "Controllers", "Models", "Helpers" etc. I have a directory called Files ...

Ruby on Rails conditional routing

I have a site listing many jobs, but I also want each account to be able to access its jobs in one place. Thus, I am using these routes: map.resources :jobs map.resource :account, :has_many => :...

Clean URL s using OpenCart s router class

How do you write clean URL s in OpenCart using their built in Router class? Here is my .htaccess file: RewriteEngine On RewriteRule ^(system) - [F,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{...

subdomain routing to multiple controller issue

I have a site: www.mydomain.com where we have administrative controls hidden away from normal customer view. I would like to only access the administrative features under a subdomain such as admin....

Can controller names in RESTful routes be optional?

With a standard map.resource routing mechanics and several nested resources the resultant routes are unnecessarily long. Consider the following route: site.org/users/pavelshved/blogs/blogging-horror/...

Help with rails routes

Im having a little trouble setting up routes. I have a users controller/model/views set up restfully so users is set up to be a resource in my routes. I want to change that to be usuarios ...

热门标签