簡體   English   中英

mvc將動作控制中的所有請求重定向到其他動作

[英]mvc redirect all request in action control to other action

我希望所有從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"}
        );

嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM