简体   繁体   中英

How to route by name net core mvc

I have one question - how to set route in view

<form>
<button asp-action="nextOne">Route by name</button>
</form>

By this name of route - nextOne (my Startup.cs)

app.UseEndpoints(endpoints =>
        {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");

        endpoints.MapControllerRoute(
            name: "nextOne",
            pattern: "home/magic",
            defaults: new { controller = "Home", action = "Magic" }
                );
        });

I know, I can't use asp-action but I left it to show what I want to do. What instead asp-action? Once again, I want to use name "NextOne".

Please - don't give me "unlikes", but give me an answer..

Change asp-action to asp-route :

<form>
    <button asp-route="nextone">Route by name</button>
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM