Share via

RedirectToRoute question

Stesvis 1,041 Reputation points
2021-05-26T18:28:03.337+00:00

I have a project using MVC 5 Web APIs.
In one of my ApiController(s) I need to use the return RedirectToRoute(name, routeValues) method.

The problem I have is that I don't know how to get the name of the destination route . Is there an [Attribute] that allows me to set the name of each route?

Developer technologies | ASP.NET Core | Other
0 comments No comments

Answer accepted by question author

Chao Deng-MSFT 801 Reputation points
2021-05-28T07:14:30.777+00:00

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. Chao Deng-MSFT 801 Reputation points
    2021-05-27T02:41:45.563+00:00

    Hi @Stesvis ,

    You can refer to the demo below.

    Controller:

    public class TestController : Controller  
        {  
            // GET: Test  
            public ActionResult Index()  
            {  
                return View();  
            }  
      
            public ActionResult Test()  
            {  
                return RedirectToRoute(new  
                {  
                    controller = "Test",  
                    action = "Index",  
                     
                });  
            }  
        }  
    

    When you visit the Test method in TestController, he will be redirected to the Index page.

    Result:

    100044-fasfafafasfwetwet.png

    You can also view more usage of RedirectToRoute.


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    ChaoDeng

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.