Configure routes using ASP.NET MVC 5 areas

2

I'm trying to set up a route using area as follows:

No RouteConfig.cs

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 = "Home", action = "Index", id = UrlParameter.Optional }
    );
    }
}

I created an area called "Adm" and AdmAreaRegistration.cs is as follows:

public class AdmAreaRegistration : AreaRegistration 
{
    public override string AreaName 
    {
        get 
        {
            return "Adm";
        }
    }
    public override void RegisterArea(AreaRegistrationContext context) 
    {
        context.MapRoute(
            "Adm_default1",
            "Adm/{controller}/{action}/{id}-{descricao}",
            new {controller = "EntradaDeUniformes", action = "Exibir"}
        );
        context.MapRoute(
            "Adm_default",
            "Adm/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }
}

Uniform InputController.cs that is inside the Adm / Controllers folder

    public ActionResult Exibir(int? id, string descricao)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        EntradaDeUniforme entradaDeUniforme = db.EntradaDeUniformes.Find(id);
        if (entradaDeUniforme == null)
        {
            return HttpNotFound();
        }
        return View(entradaDeUniforme);
    }

But when I try to pass:

http://localhost/escola/Adm/EntradaDeUniformes/Exibir/1-Calça-Azul

Return this error:

Am I doing something wrong or missing something?

    
asked by anonymous 01.06.2015 / 01:01

1 answer

2

How I configured the route this way "Adm/{controller}/{action}/{id}-{descricao}"

When I passed http://localhost/escola/Adm/EntradaDeUniformes/Exibir/1-Calça-Azul

It did not work because "Blue" was understood as another parameter because of "-".

So I did it differently in AdmAreaRegistration.cs :

context.MapRoute(
            "Adm_default1",
            "Adm/{controller}/{action}/{id}/{descricao}",
            new {controller = "EntradaDeUniformes", action = "Exibir"}
        );

Passing:

http://localhost/escola/Adm/EntradaDeUniformes/Exibir/1/Calça-Azul

That works perfectly!

    
05.06.2015 / 19:19