简体   繁体   English

在 C# ASP.NET Core 3.1 应用程序中,我如何路由到 controller 然后查询字符串?

[英]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.

相关问题 ASP.NET Core 3.1:如何路由到子文件夹中的 controller - ASP.NET Core 3.1 : how to route to a controller in a sub folder 如何在 asp.net 核心 3.1 mvc web 应用程序中将日志保存到数据库? - How do I save logs to database in asp.net core 3.1 mvc web application? ASP.NET Core 3.1 路由(Route, ActionName)本地化怎么做? - How to do ASP.NET Core 3.1 routing (Route, ActionName) localization? 如何使用 C# 迭代当前为字符串的数组并在我的 ASP.NET Core 应用程序中添加其他值? - How do I iterate over an array that's currently a string using C# and add additional values in my ASP.NET Core Application? 如何使ASP.NET正确路由控制器? - How do I get ASP.NET to route a controller properly? 如何在共享服务器上托管的 ASP.Net Core 3.1 应用程序中存储生产机密,如连接字符串 - How can I store production secrets like connection string in ASP.Net Core 3.1 application, hosted on a shared server 如何在使用 EF 的 asp.net core 3.1 MVC 应用程序中正确使用我的 SQLite 数据库? - How do I properly use my SQLite db in my asp.net core 3.1 MVC application using EF? Asp.net 核心 3.1- 我如何从 Controller 返回到 Razor 页面? - Asp.net Core 3.1- How can I return from Controller to Razor Page? 使用 ASP.NET Core 3.1,如何从页面 URL 中剥离主页 controller? - With ASP.NET Core 3.1, how can I strip the Home controller from a page URL? 如何使用 C# 在 ASP.NET Core 3.1 MVC 中使用会话变量 - How to use session variables in ASP.NET Core 3.1 MVC using C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM