Hi @Stesvis ,
You can check the official documents here, I hope it helps you.
https://learn.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
RedirectToRoute question
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?
-
Chao Deng-MSFT 796 Reputation points
2021-05-28T07:14:30.777+00:00
1 additional answer
Sort by: Most helpful
-
Chao Deng-MSFT 796 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:
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