[RESOLVED]Frustrating MVC "404" error when trying to use Areas

This will (hopefully) be an easy one for an experienced MVC developer to solve.  It has me frustrated to death, however.  What am I missing?

I inherited an MVC project from a programmer whose last act was to separate it into Areas.  I’ve included a screen snapshot of the VS solution file below with the portions relevant to this description highlighted.  The problem I’m encountering is "404 not
found" errors when I try to use Html.ActionLink() to reference views in areas other than the one generating the link.  To start from scratch and isolate the problem, I’ve tried the following steps:

1. Create a new area by right-clicking the areas folder and "Add | Area"
2. Named the new area "DocumentUploaderNew"
3. Created a new controller by right-clicking DocumentUploaderNew and "Add | Controller"
4. I’ve named my new controller "FileUploadController"
5. Created a new view by right-clicking DocumentUploaderNew and "Add | View"
6. I’ve named my new view "FilerUploader.cshtml"

Now, in one of the other areas ("UserAccount") I have a view named "MyAccount.cshtml".  It contains two pieces of markup relevant to this problem:

          @Html.ActionLink("Upload Documents", "FileUploader", new { controller = "FileUpload", area = "DocumentUploaderNew" }, new { @class = "btn btn-info" })


         @Html.ActionLink("Edit Questions", "ChangeQuestions", new { controller = "Account", area = "UserAccount" }, new { @class = "btn btn-info" })

The second link (to "ChangeQuestions") works perfectly.  The first (to "FileUploader") fails with the following error.  The only difference I can see is that for the working link, the reference is to a view within the same area as the "calling" page.  The
link that doesn’t work is to a view in a different area.  This seems like such a simple thing–and I’m sure it is–but I cannot find it.  Thanks in advance for any and all help.

The resource cannot be found.

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.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /CROMERR.Website/DocumentUploaderNew/FileUpload/FileUploader

do you have an FileUploader action in the FIleUpload controller?

Thank you for the reply ignatandrei.  I do, but stupid question: how does the action name in the controller relate to the name of the view (the .cshtml file)?  You may have pinned this down for me.  I had to do some renaming when I started trying to build
my workarounds of what the previous programmer left me.  Some of the names I chose were the obvious ones he picked, and MVC was barfing on name conflicts.  I wonder if I have messed something up in my renaming? 

Hi MarcAaron,

First, you need have a folder in the Views which name is the same as the controller name and the views should be in that folder or in Shared folder. So please put the view file (FileUploader.cshtml) to FileUpload folder.

Secondly, by default the view name should be the same as action name unless you specify the view name. (return View(“viewname”)

Best Regards


Thank you Starain.  It looks like that was the problem.  It looks like I got myself into a bind with the renaming… the previous programmer had already used the default view name elsewhere and MVC was barfing on that, so I had to give my .cshtml file a
different name.  I’ve started from scratch with some guaranteed unique names and all is well now.

I am unsure why the naming would be an issue across separate areas but, again, I am new to this and could be doing something wrong.  And/or, having inherited a broken project, perhaps there are some configuration issues the previous programmer left me to
deal with.  Regardless, it looks like I’m off and running again.  Thank you.

Leave a Reply