开发者

What are some alternatives to RedirectToAction?

开发者 https://www.devze.com 2023-01-05 04:56 出处:网络
On my HomeController I have an index action which redirects to the index action of the CustomerController via the RedirectToAction method. In this instance I don\'t like how RedirectToAction modifies

On my HomeController I have an index action which redirects to the index action of the CustomerController via the RedirectToAction method. In this instance I don't like how RedirectToAction modifies the URL showing mysite开发者_如何学Go.com/Customer. Are there some alternative mechanisms to performing a redirection that will allow me to still leverage the index action from the CustomerController?

public RedirectToRouteResult Index()
{
    return RedirectToAction("Index", "Customer");
}


As I understood it, RedirectToAction uses a reverse lookup on the routing table to generate its URL. So if you've told the Routing module that you want to map "/Customer/Index" to Controller Customer and Action Index then RedirectToAction will take your Index and Customer arguments and convert them to "/Customer/Index".

So if you want to change the behaviour of RedirectToAction you simply need to change your routing rules.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号