Areas - How to make a directory appear before Controller/Action/ on the route?

Asked

Viewed 23 times

0

Hello.

I created a web project ASP.NET MVC Core in the Visual Studio 2019 and I created an area called Managerial. Inside it, in the Views folder I created a subfolder called Products and put some views inside it.

My routes are like this:

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "areas",
                    template: "{area:exists}/{controller=Produtos}/{action=index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

The folder structure is like this:

inserir a descrição da imagem aqui

I would like the browser url to appear:

localhost:{port}//Manager/Products/(register for example)

It is possible to do this?

1 answer

0


I resolved.

I used the following route:

routes.MapAreaRoute(
                name: "areas",
                areaName: "Gerencial",
                template: "Gerencial/{controller=Produtos}/{action=index}/{id?}");

The URL went the way I wanted it to. If anyone wants to add anything I’d appreciate it.

Browser other questions tagged

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