我如何在 C# mvc 中将 3 个参数路由到控制器?
How I do route passing 3 parameters into controller in C# mvc?
url格式为:
http://0.0.0.0:5000/?id=author_name&id2=book_name&id3=123
我试图为它做路由,但它不起作用:
routes.MapRoute(
name: "default",
template: "{controller=Main}/{action=Index}/{id?}&{id2?}&{id3?}");
方法是:
public IActionResult Index(string id, string id2, string id3)
{
return View();
}
如何设置传递 3 个参数的正确路径?
我相信这个问题已经在这里被问到并得到回答:Routing with Multiple Parameters using ASP.NET MVC
我很确定您的情况不需要将查询字符串放在路由模板中。它将由 mvc 自动完成。只需使用 "normal" 路线。
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional }
);
get中的变量自动作为参数传递。
public IActionResult Index(string id, string id2, string id3)
{
return View();
}
url格式为:
http://0.0.0.0:5000/?id=author_name&id2=book_name&id3=123
我试图为它做路由,但它不起作用:
routes.MapRoute(
name: "default",
template: "{controller=Main}/{action=Index}/{id?}&{id2?}&{id3?}");
方法是:
public IActionResult Index(string id, string id2, string id3)
{
return View();
}
如何设置传递 3 个参数的正确路径?
我相信这个问题已经在这里被问到并得到回答:Routing with Multiple Parameters using ASP.NET MVC
我很确定您的情况不需要将查询字符串放在路由模板中。它将由 mvc 自动完成。只需使用 "normal" 路线。
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional }
);
get中的变量自动作为参数传递。
public IActionResult Index(string id, string id2, string id3)
{
return View();
}