【问题标题】:pass parameters as per url in routing在路由中根据 url 传递参数
【发布时间】:2016-10-10 21:56:03
【问题描述】:

我想将参数从一个动作传递到另一个动作。 我的 url 路由如下:

 routes.MapRoute("SearchDealbyPrice", "Deal/CategoriesID/{CategoriesID}/FromPrice/{FromPrice}/ToPrice/{ToPrice}/Price/{Price}/GreenCars/{GreenCars}/PageName/{PageName}", defaults: new { controller = "Deal", action = "Index" });

我需要显示如下网址:

Deal/CategoriesID/9/FromPrice/100/ToPrice/200/Price/0/GreenCars/0/PageName/Garrage

如何从控制器实现这一点? 我需要从控制器传递这些参数,并且 URL 应该像上面那样显示。

谢谢 拉丽莎

【问题讨论】:

    标签: asp.net-mvc routing


    【解决方案1】:

    这是你要找的吗? 我已将您的路线添加到 RouteConfig 并在 DealController 中放置了一个 RedirectExample 方法:

    public ActionResult RedirectExample() {
          return RedirectToRoute("SearchDealbyPrice", new {CategoriesID = 9,FromPrice = 100,ToPrice = 200,Price = 0,GreenCars = 0,PageName= "Garrage"}); }
    

    它工作正常。当我转到http://localhost:51639/Deal/RedirectExample 时,路由重定向到 Deal 控制器中的 Index 方法,结果 URL 如下http://localhost:51639/Deal/CategoriesID/9/FromPrice/100/ToPrice/200/Price/0/GreenCars/0/PageName/Garrage

    【讨论】:

    • 谢谢。我试过如下: return RedirectPermanent("Deal/CategoriesID/" + categoryId + "/FromPrice/" + model.FromPrice + "/ToPrice/" + model.ToPrice + "/Price/" + model.IsBusinessPrice + "/ GreenCars/" + isGreenCars + "/PageName/SpecialGarage");.它也在工作
    • 嗨 Lukas,对不起,我不知道如何接受这个答案。你能指导我吗?
    猜你喜欢
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 2021-01-17
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多