Arnold Smith
Arnold Smith

Reputation: 303

MVC Area View not found in deployed app. HTTP 404 Error

I’m hoping that someone can set me straight on an issue I have with MVC Areas. I know that this question has been asked before, but I am not able to see the error in my code. In an intranet app I inherited I created another ActionResult method in an existing Administration Area controller and a corresponding View.

ActionResult AllCurrentAttributes()

It takes no parameters and works when I operate the app in the VS 2012 IDE. The deployed app, however, throws the error: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Other ActionResult methods in the same controller work perfectly.

All of the other working routes are registered in AdministrationAreaRegistration.cs.

public override void RegisterArea(AreaRegistrationContext context)
{
  context.MapRoute(
    "RA",
    "Administration/RA/{raId}",
    new { area = "Administration", controller = "RA", action = "View" },
    new { riskAssessmentId = @"\d+" },
    new[] { "LargeApp.UI.Web.Areas.Administration.Controllers" }
    );

  context.MapRoute(
    "RA Work",
    "Administration/ RA /Work/{raId}",
    new { area = "Administration", controller = " RA ", action = "Work" },
    new { riskAssessmentId = @"\d+" },
    new[] { " LargeApp.UI.Web.Areas.Administration.Controllers" }
    );

  context.MapRoute(
    "All Current Attributes",
    "Administration/ RA /AllCurrentAttributes/",
    new { area = "Administration", controller = " RA ", action = "AllCurrentAttributes" },
    new[] { " LargeApp.UI.Web.Areas.Administration.Controllers" }
    );

  context.MapRoute(
    "Administration Default",
    "Administration/{controller}/{action}/{id}",
    new { area = "Administration", controller = "Home", action = "Index", id = UrlParameter.Optional },
    new[] { " LargeApp.UI.Web.Areas.Administration.Controllers" }
    );
}

The ActionLink in Index.cshtml, a View created for the Home controller located in the Administration Area, looks like this:

@Html.ActionLink("All Current Attributes", "AllCurrentAttributes", "RA")

The View is located in the RA folder within the Administration Area and is named AllCurrentAttributes.cshtml. Other ActionLinks within Index.cshtml that reference the same RA controller work perfectly.

@Html.ActionLink("Work Rules", "WorkIndex", "RA ")
@Html.Action("List", "RA ") 

In Global.asax, AreaRegistration.RegisterAllAreas() is called in Application_Start before RegisterRoutes(RouteCollection routes) is called. In RegisterRoutes the default route code looks like this:

routes.MapRoute(
    "Default", 
    "{controller}/{action}/{id}", 
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
    new[] { "LargeApp.UI.Web.Controllers" } 
);

Does anyone see how I might resolve the 404 error?

Thanks!

Upvotes: 1

Views: 859

Answers (2)

Arnold Smith
Arnold Smith

Reputation: 303

I do not understand why an @Html.ActionLink does not work. But in the interest of keeping things moving I have used another kind of link:

@Html.RouteLink("All Current Attributes", "AllCurrentAttributes", "RA")

The difference between the two types of links is explained succinctly by Chad Moran at this StackOverflow url:

What's the difference between RouteLink and ActionLink in ASP.NET MVC?

Using @RoutLink I am able to specify a route rather than rely on a pattern match of routes.

Upvotes: 0

Ognyan Dimitrov
Ognyan Dimitrov

Reputation: 6263

Can you check if there is "Areas" folder created on the IIS you deployed?

Upvotes: 0

Related Questions