Configure MVC route

2

Within the Controller folder of my MVC project I have created a subfolder called registers, which contains a controller called Cadasters (the registration module home page) and the other controllers on each page.

Within the view folder, I have a similar structure, where within the sub-folder Cadasters I have the view index (for the home 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 drivers that are outside of the registry subfolders, such as QueryUM.

It works correctly 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 query screen, it reloads the page with the localhost:63892/Cadastros/ConsultaUM link.

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

return View("Index", consultaUm);

Does anyone know where I'm going wrong?

    
asked by anonymous 20.07.2016 / 20:42

1 answer

0

Possibly if Controller should 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 { ... }
}
    
25.07.2016 / 22:23