【问题标题】:Url routing with parameters not working in MVC带有参数的 URL 路由在 MVC 中不起作用
【发布时间】:2013-04-14 21:44:33
【问题描述】:

这是我的操作链接

 @Html.ActionLink(item1.TranslatedName,"Index","Properties",new { CategoryId=item1.CategoryId,CategoryName=item.CategoryName},null)

当前生成的url是 http://abc.com/Properties/?CategoryId=1&CategoryName=Banken 它也不会调用控制器的索引视图。如果我手动将 url 更改为
http://abc.com/Properties/Index?CategoryId=1&CategoryName=Banken 它的工作原理

我为此定义的路线是

 routes.MapRoute(
            "Properties", // Route name
            "{controller}/{action}/{CategoryId}/{CategoryName}", // URL with parameters
                new { controller = "Properties", action = "Index" }, // Parameter defaults
            new { CategoryId = @"\d+", CategoryName = @"\d+" }
        );

谁能告诉我我做错了什么?

我需要显示的网址是 http://abc.com/Properties/Banken 基本上我想隐藏类别ID并显示类别名称

【问题讨论】:

  • 1.此路由是否在默认路由之前定义? (针对问题1) 2. 您不能隐藏中间(不是最后一个)路线段。

标签: asp.net-mvc asp.net-mvc-4 url-rewriting


【解决方案1】:

如果你想要它像 Properties/Banken,你应该将你的 index 动作重命名为 banken 动作,我也不确定你是否可以隐藏 id

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 2015-08-13
    • 1970-01-01
    • 2018-03-11
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多