mvc将操作控制中的所有请求重定向到其他操作

时间:2013-10-08 09:06:59

标签: c# asp.net-mvc asp.net-mvc-routing

我希望localhost / Other_Data的所有请求都移动到localhost / Other_Data / index2?id_Mode = 1& city =“ddd” 但我不喜欢使用重定向我想使用路由 可能会帮助我...... 感谢

public class SupperController: Controller
{

    public virtual ActionResult Index()
    {
...
    } 
}

public class Other_Data:SupperController
{

    public ActionResult Index2(int Id_Mode, string city)
    {
....
..
    } 
}

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

        routes.MapRoute(
            name: "Default1",
            url: "Other_Data/",
            defaults: new { controller = "Other_Data", action = "Index2", Id_Mode = 1, city="ddd"}
        );

1 个答案:

答案 0 :(得分:0)

试试这个

routes.MapRoute("Other_Data" , "Other_Data/index2/{id_Mode}/{city}" , 
 new { controller = "Other_Data", action = "index2",id_Mode=1,city="ddd" });