asp.net core mvc - MVC6 route choosing wrong action -
i'm trying make simple webpage more 1 parameter coming in.
when click on link, takes me /links/index/1/2 instead of /links/canvas/1/2 expected.
controller:
public class linkscontroller : controller { public iactionresult index(int? id) { ...... return view() } public iactionresult canvas(int param1, int param2) { ...... return view() } }
page link that's not working:
<a asp-route="newroute" asp-route-param1="1" asp-route-param2="2">view</a>
startup.cs:
app.usemvc(routes => { routes.maproute( name: "newroute", template: "{controller=links}/{action=canvas}/{param1}/{param2}"); routes.maproute( name: "default", template: "{controller=home}/{action=index}/{id?}"); });
the default values specified in route used if there not value, when use route in context values populated controller , action values of page viewing rather default values.
you can override controller , action values changing code this:
<a asp-controller="links" asp-action="canvas" asp-route-param1="1" asp-route-param2="2">view</a>
Comments
Post a Comment