0

I am receiving an IIS 404 error message when I try to go to the index method in my home controller in the agency area. If I update the route attribute to: [Route("{action}")] it works fine, but I want to keep index as the default route.

In my view I have this:

@Html.ActionLink("Click here", "index", "home", new { area = "agency" }, new { @class = "btn btn-block btn-lg btn-primary" })

HomeController in Agency Area

namespace ProjectName.UI.Areas.Agency.Controllers
{
    [RouteArea("agency")]
    [RoutePrefix("home")]
    [Route("{action=index}")]
    public class HomeController : BaseController
    {

        public ActionResult Index()
        {
            return View();
        }
    }
}

RouteConfig:

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

    routes.MapMvcAttributeRoutes();
    AreaRegistration.RegisterAllAreas();

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "home", action = "index", id = UrlParameter.Optional },
        namespaces: new[] { "ProjectName.UI.Controllers" }
    );
}

I also have an Admin Area that looks exactly the same as the Agency area, except the RouteArea is admin and I don't have any problems.

Any suggestions would be welcomed.

Andrew
  • 2,013
  • 1
  • 23
  • 38

1 Answers1

0

I found that the problem was because my area was called Agency and in my Views folder I had another subfolder called Agency. Instead of routing to agency/home/index it was trying to find a home view inside my agency folder.

Andrew
  • 2,013
  • 1
  • 23
  • 38