Area routing problem using MVC .Net

2

I am working on a project that has a presentation layer with several Areas, and it is difficult for me to test the application, since the controllers and views that I am developing, are in a defined area.

I was looking for information about working with areas, and although the definition of the area is clear, I can not establish that when I start the application, the driver and view by default, are the ones that I indicated in the configuration.

In the RouteConfig.cs file, I tego this:

using System.Web.Mvc;
using System.Web.Routing;
namespace XXX.Inv.Odin.Web
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new { controller = "NegocioCompra", action = "Index", id = UrlParameter.Optional }
            //);

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                //defaults: new { controller = "NegocioCompra", action = "Index", id = UrlParameter.Optional }
                defaults: new { controller = "BusquedaInicial", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

And in the area where I am working, (well Root) I have the following:

using System.Web.Mvc;

namespace XXX.Inv.Odin.Web.Areas.BienRaiz
{
    public class BienRaizAreaRegistration : AreaRegistration 
    {
        public override string AreaName 
        {
            get 
            {
                return "BienRaiz";
            }
        }
        public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "BienRaiz_default",
                "BienRaiz/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

Here is a picture of how the project is outlined in the project explorer:

Does anyone have an idea that I'm doing wrong?

    
asked by Luis Gabriel Fabres 19.01.2017 в 16:57
source

2 answers

3

Your AreaRegistration should be structured in this way

public class ForumAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get { return "BienRaiz";  }
    }
    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "BienRaiz_default",
            "BienRaiz/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "BienRaiz.Controllers" }//referencia a los controladores de esta área
        );
    }
}

and in your RouteConfig

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        //defaults: new { controller = "NegocioCompra", action = "Index", id = UrlParameter.Optional }
        defaults: new { controller = "BusquedaInicial", action = "Index", id = UrlParameter.Optional },
        namespaces: new string[] { "XXX.Inv.Odin.Web.Controllers" }//haciendo referencia a los controladores del proyecto main
    );
}

Practically all you need is the reference to the controllers of each application.

    
answered by 19.01.2017 / 17:18
source
0

Please specify the reference well

namespaces: new string[] { "XXX.Inv.Odin.Web.Controllers" }

that you have to put in each point

    
answered by 08.11.2017 в 17:14