gpt4 book ai didi

asp.net-mvc - 在mvc3中添加带有url的额外参数

转载 作者:行者123 更新时间:2023-12-02 06:02:58 26 4
gpt4 key购买 nike

我是 ASP.NET MVC3 的新手。我想在 Controller 之前添加带有 url 的额外参数,例如:-

Newparameter/{controller}/{action}/{id};

是否可行,我还需要更改其值。

请帮忙......

最佳答案

是的,这是可能的,只需在 Global.asax 中添加一条新路线,如下所示:

routes.MapRoute(
"Default with new param", // Route name
"{newParameter}/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

将其放在默认路由之前,因为它更具体。

然后创建一个将“newParameter”作为方法参数的操作方法

关于asp.net-mvc - 在mvc3中添加带有url的额外参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13308858/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com