简体   繁体   English

MVC路由到博客类别

[英]MVC Routing to a Blog Category

I already have a route in the RouteConfig , to redirect to the Archive Action when there is a year and a month :- 我已经在RouteConfig有了一条路由,可以在RouteConfig后重定向到Archive Action:

routes.MapRoute("Blog", "Blog/{action}/{id}",
new
{
    controller = "Blog",
    action = "show",
    id = ""
});

Now I wish to have another MapRoute that redirect to the Archive Action when there is a category, for example Blog/Archive?catId=2 . 现在,我希望有另一个MapRoute可以在存在类别(例如Blog/Archive?catId=2时重定向到Archive Action。

How can I achieve that? 我该如何实现?

In your RouteConfig you can add 在您的RouteConfig中,您可以添加

routes.MapRoute("Archive", "Blog/Archive", new {controller = "Blog", Action = "Archive" });

In you controller you can have this action 在您的控制器中,您可以执行此操作

public void Archive(int catId) {
    ...
}

This will automatically map catId query string value to the catId variable. 这将自动将catId查询字符串值映射到catId变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM