gpt4 book ai didi

c# - MVC : actions that don't exist

转载 作者:太空宇宙 更新时间:2023-11-03 19:35:15 25 4
gpt4 key购买 nike

我没有做过多少 MVC,并且仍在学习如何做事的艰难方法。

MVC 1 和 C#

问题我想为客户提供一个链接,例如 www.temp.com/redirects/cust100?id=123&url=www.nothere.com

从 URL 我知道它将转到“重定向”的 Controller ,但没有“cust100”的操作。我如何创建一个将获取操作的 ActionResult(或其他东西)以便我可以在将它们重新路由到我网站上的其他位置之前针对数据库查询它以检查它是否有效?

如果我已经解释得太好了,请随时提出更多问题。

亲切的问候,皮特

最佳答案

您的路线:

routes.MapRoute("Redirects",               
"{controller}/{cust}",
new {controller = "redirects", action = "Index", cust = "" });

这将通过将参数作为默认操作发送到 index 方法来使您的 url 工作:

/redirects/cust100?id=123&url=www.nothere.com

还有你的 Controller 方法:

public ActionResult Index(string cust, int id, string url)     
{
// do some DB stuff
return RedirectResult(url);
};

关于c# - MVC : actions that don't exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2056512/

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