在C#ASP.NET Core 3.1应用程序中,我如何路由到控制器然后查询字符串?
我有一个视图设置为:
然后我有我的业务控制器:
[Route("{business}/{url}")]
public IActionResult business(string url)
{
return View();
}
我的目的是能够像
https://website.com/business/business-name-123
business> business-name-123
然后接收为参数。
在您通过?query =网站名< / code>之前,我已经创建了类似的东西?
I have a view setup as:
I then have my Business 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
https://website.com/business/business-name-123
The business-name-123
is then received as the parameter.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在路由模板中删除
{business}
周围的括号。业务是一个恒定的字符串,而不是路由参数:Remove the braces around
{business}
in your route template. Business is a constant string, not a route parameter: