Html.Beginform error with area

Asked

Viewed 71 times

2

I have a view with the following form:

@using (Html.BeginForm("Salva", "Blog", new { area = "admin" }, FormMethod.Post, false, new { id = "formCadastro" }))

However, when clicking on Ubmit the url that appears is the following

But I need her to show up like this:

My mapping is as follows:

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

            endpoints.MapAreaControllerRoute(
                name:"Admin",
                areaName: "Admin",
                pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
        });

But I’ve used it too:

app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapControllerRoute("Admin", "{controller=Home}/{action=Index}/{id?}");
        });
  • I would recommend you to stop using this kind of syntax in this version of mvc and switch to the new Razor markup template. Take a look at this tutorial https://docs.microsoft.com/pt-br/aspnet/core/tutorials/razor-pages/? view=aspnetcore-2.2

1 answer

0

  • I came to use this way too, and it didn’t work. I believe it is something related to the routing of the area.

  • If the front-end is calling the wrong url I think it is unlikely to be the route configuration. But if you really think it’s route setup, try adding this attribute to your controller: [Area("Admin")]

  • I put this on and it still didn’t work

  • What version of Asp.net Core you are using?

  • if I’m not mistaken, it’s the 3.0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.