【问题标题】:ASP.NET MVC 3: Redirect from one controller to another controller and URL rewriteASP.NET MVC 3:从一个控制器重定向到另一个控制器和 URL 重写
【发布时间】:2012-04-19 14:43:53
【问题描述】:

假设我们有三个控制器(ASP.NET MVC3):

- NewProductController (view ->index)
- ProductModelController (view ->index(int productid))
- ProductDetailsController (view =>index(int productid, int productModelId))

用户可以从 NewProductController 的索引视图中选择产品或产品+产品型号。 根据选择,我们需要重定向到 ProductModelController 或 ProductDetailsController 的索引视图。请指导我如何做到这一点。

我们希望将 URL 重写为类似

的东西,而不是在 URL 中显示控制器的名称
http://www.myDomain/List of product
http://www.myDomain/List of LG TV

请建议我执行此操作的最佳方法。

谢谢, 保罗

【问题讨论】:

标签: asp.net-mvc-3 url-rewriting hyperlink redirect


【解决方案1】:

使用 1 个控制器和 3 个视图。像这样

ProductsController(int? productid, int? productModelId)
{
    if(productModelId.HasValue){
    //Some code to create model
       return View("Details",Model)
    }
    else if(productid.HasValue){

    //Some code to create model
       return View("ProductModel",Model)
    }


    //Some code to create model
       return View("NewProduct",Model)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 2019-10-17
    • 2018-02-11
    • 2023-04-10
    相关资源
    最近更新 更多