Set up MVC route

Asked

Viewed 213 times

2

Inside the Controller folder of my MVC project I created a subfolder called Entries, which contains within 1 controller called Entries (home page of the registration module) and the other controllers of each page.

Inside the view folder, I have a similar structure, where inside the Register subfolder I have the Index view (for the initial page) and the other views of the module.

In the route configuration file, I left it as follows:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Cadastros",
            url: "Cadastros/{controller}/{action}/{id}",
            defaults: new { controller = "Cadastros", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "Aperam.PCP.PNB.UI.Controllers.Cadastros" }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "Aperam.PCP.PNB.UI.Controllers" }
        );

I have other controllers who are outside the registration subfolders, for example Consult a.

It works properly when I try to access the addresses:

  • localhost:63892/Cadastros
  • localhost:63892/Cadastros/MotivoRealocacao
  • localhost:63892/ConsultaUM

However, when I perform any operation on the ONE query screen, it reloads the page with the link localhost:63892/Cadastros/ConsultaUM.

In the return of the search action for example, the return of the controller is

return View("Index", consultaUm);

Does anyone know where I’m going wrong?

1 answer

0

Possibly if Controller must have the namespace of the first route:

namespace Aperam.PCP.PNB.UI.Controllers.Cadastros 
{
    public class ConsultaUMController : Controller { ... }
}

Switch to:

namespace Aperam.PCP.PNB.UI.Controllers
{
    public class ConsultaUMController : Controller { ... }
}
  • Hello. I just checked and the namespace is already as your second item.

  • You’re sure there’s no other Controller by that name ConsultaUM inside Cadastros?

  • I checked again and there is no other controller with this name. I really don’t understand why after a request is added the "/Registrations" in the URL

  • When I have a little time, I’ll do a test on a similar structure, then I’ll respond again.

Browser other questions tagged

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