ASP.NET CORE MVC - Redirecting same action to another controller in view

Viewed 2292

In my View I have standard Edit action next to each row in View:

@model IEnumerable<MyProject.Models.Person>
...
    <a asp-action="Edit" asp-route-id="@item.NameID">Edit</a> //

When clicked it goes to:

https://localhost:44312/Person/Edit/1 in case you are editing 1st row in View. That's standard behavior.

My question is how can I redirect that same action for same IDs to another controller? For example to:

https://localhost:44312/People/Edit/1

1 Answers

Add asp-controller="controllerName"

In your case:

<a asp-controller="People" asp-action="Edit" asp-route-id="@item.NameID">Edit</a>
Related