gpt4 book ai didi

asp.net-mvc-3 - 带参数的 MVC 索引方法的 Clean Url

转载 作者:行者123 更新时间:2023-12-02 05:10:55 24 4
gpt4 key购买 nike

我是 MVC 新手,Google 没有提供太多帮助,所以我会在这里询问。我想做的很简单(我原以为)我想将一个字符串传递给索引方法,但它通常看起来像:

http://mydomain.com/home/index/mystring

我想要:

http://mydomain.com/mystring

我该怎么做?

最佳答案

您可以在 Global.asax 中定义以下路由:

routes.MapRoute(
"MyStringRoute",
"{*mystring}",
new { controller = "Home", action = "Index" }
);

它将调用 Home Controller 的 Index 操作:

public class HomeController : Controller
{
public ActionResult Index(string mystring)
{
return View();
}
}

关于asp.net-mvc-3 - 带参数的 MVC 索引方法的 Clean Url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5999503/

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