ASP.NET Core MVC中的路由

发布于 2025-01-28 00:37:45 字数 134 浏览 2 评论 0原文

如何在URL中创建这样的路由,

Localhost:4578//Home/Index/1/2/3/4/5/6 

我尝试使用ASP.NET Core 3.1 MVC中的路由来制作自定义URL。

How can I create a route like this in the url

Localhost:4578//Home/Index/1/2/3/4/5/6 

I tried making a custom url using routing in ASP.NET Core 3.1 MVC.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈甜 2025-02-04 00:37:45

首先,您不能在端口号之后使用双重斜杠,

想象一下,您有一个类别controller,

其类名称将是这样

[Route("admin/category")]
public class CategoryController : Controller

,在此之后,您将拥有返回ActionResult的方法或此控制器中的其他内容,

[Route("upper-categories/add")]
public async ActionResult UpperCategoryAdd()

您可以通过使用 /admin /category访问此方法/上类别/add

,如果要使用ID或类似的内容,

则应在其上使用{id}

[Route("upper-categories/edit/{id}")]

First you cannot use double slash after your port number,

Imagine, you have a CategoryController

Its class name will be like this

[Route("admin/category")]
public class CategoryController : Controller

and after that you will have a method returning ActionResult or something else in this controller

[Route("upper-categories/add")]
public async ActionResult UpperCategoryAdd()

You access this method by using /admin/category/upper-categories/add

and if you want to use an id or something like that

you should use {id} on it

[Route("upper-categories/edit/{id}")]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文