[英]In a C# ASP.NET Core 3.1 application how do I route to a controller then query string?
I have a view setup as:我有一个视图设置为:
I then have my Business controller:然后我有我的业务 controller:
[Route("{business}/{url}")]
public IActionResult business(string url)
{
return View();
}
My aim is to be able to pass the url string 'neatly' like so我的目标是能够像这样“整齐地”传递 url 字符串
https://website.com/business/business-name-123
The business-name-123
is then received as the parameter.然后接收business-name-123
作为参数。
I have created something similar to this before where you pass ?query=website-name
but I don't want this, can someone explain what I need to do to get this working using just the / routing aspect?在您传递?query=website-name
之前,我已经创建了类似的东西,但我不想要这个,有人可以解释我需要做什么才能仅使用 / 路由方面来使它正常工作吗?
Remove the braces around {business}
in your route template.删除路线模板中{business}
周围的大括号。 Business is a constant string, not a route parameter:业务是常量字符串,不是路由参数:
[Route("business/{url}")]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.