ASP.NET MVC检索到控制器,操作和参数的路由

时间:2022-08-29 11:01:19

In ASP.NET MVC how can I generate a URL to a specific controller and action along with other parameters. The RedirectToAction allows me to redirect, but I would like to retrieve this URL instead from within my controller.

在ASP.NET MVC中,如何生成指向特定控制器和操作的URL以及其他参数。 RedirectToAction允许我重定向,但我想从我的控制器中检索此URL。

I tried using:

我试过用:

Url.Action("Page", "Administrator", New With {.page = _currentPage})

But that returned a link like /Administrator/Page?page=2 whereas I was hoping to retrieve something like /Administrator/Page/2

但是这返回了像/ Administrator / Page?page = 2这样的链接,而我希望检索像/ Administrator / Page / 2这样的东西

I've searched countless forums and I'm sure there is something around for this, but I cannot find it for the life of me.

我搜索了无数的论坛,我确信周围有一些东西,但我找不到它的生命。

Thanks!

1 个解决方案

#1


What do your routes look like? The standard route expects an id as the third parameter. If you haven't changed your routes, try using:

你的路线是什么样的?标准路由期望id为第三个参数。如果您尚未更改路线,请尝试使用:

Url.Action( "Page", "Administrator", New With { id = _currentPage } )

#1


What do your routes look like? The standard route expects an id as the third parameter. If you haven't changed your routes, try using:

你的路线是什么样的?标准路由期望id为第三个参数。如果您尚未更改路线,请尝试使用:

Url.Action( "Page", "Administrator", New With { id = _currentPage } )