ASP.Net MVC 2 Areas: The partial view '...' was not found - asp.net-mvc

We recently upgraded a project to MVC 2 and we'd like to use Areas but there is an issue.
We have created a new area, setup a controller, configured a route, and created a view in the correct location. When we run the code it successfully finds the route and hits the controller but when it goes to render the view there is an exception.
The web forms view engine doesn't seem to be looking in the Areas section for views. The error we're seeing is:
~/Views/<ControllerName>/<ViewName>.aspx
~/Views/<ControllerName>/<ViewName>.ascx
~/Views/Shared/<ViewName>.aspx
~/Views/Shared/<ViewName>.ascx
When it should be:
~/<AreaName>/Views/<ControllerName>/<ViewName>.aspx
~/<AreaName>/Views/<ControllerName>/<ViewName>.ascx
~/<AreaName>/Views/Shared/<ViewName>.aspx
~/<AreaName>/Views/Shared/<ViewName>.ascx
~/Views/<ControllerName>/<ViewName>.aspx
~/Views/<ControllerName>/<ViewName>.ascx
~/Views/Shared/<ViewName>.aspx
~/Views/Shared/<ViewName>.ascx
This would indicate that it's still somehow using the MVC 1 dll but we've looked carefully and can find only references to the V2 of MVC (there was a V1 reference in xVal, a third party DLL, but fixing that didn't make a difference).
I can only imagine that we missed something when we did the upgrade or that we've got some unusual edge case because there doesn't seem to be anything on the web that matches the problem we're experiencing.
What things could we look at that might help us resolve this issue?
Thanks in advance for any help provided.
Cheers,
Zac

What things could we look at that might help us resolve this issue?
Make sure Area Routes are Registered AreaRegistration.RegisterAllAreas(); are registered first. Area routes need to be registered as well.
Make sure generated URL links have the area name included as one of the arguments when using ActionLink and other related URL helpers
Sometimes just delete and re-add the Area from scratch. Sounds silly, but it works.
The related SO question on the left hand side of this page may help. I have linked one I think may be of value

Related

ASP.NET MVC Issues - Namespace not found

Basically any place that a MVC resource is needed in my application, it is being listed in the error list (234 errors, almost every single one is the exact same error).
I am able to get intellisense when I type System.Web.Mvc., and add a Controller, but after building, the line which the Controller was added to shows in blue font, but it is underlined.
I have literally tried so many solutions from Stack, most often discussed is:
Remove reference to System.Web.Mvc and re-add. Set copy local to true.
Screenshot of subset of errors below.
I am surprised that it is being flagged here, when it is recognizing Controller in the inheritance.
Here too
This is never the nice answer... I recreated the solution, and very carefully chose all of my options when configuring. I built to the browser after all changes, and so far everything is working out.

asp.net mvc area Routes stopped Working

I have had a working project for months now....This week I decided to change some of my areas....I deleted two areas and created a new Area...
After doing this I can't add any new controllers to the existing areas and get them to route correctly. I am seeing other strange things....for instance I am not getting autocompletion of the services path....It only list the controllers within the areas and not the models or the services....
I have created new controllers in the new areas...and these worked fine.....but something is messed up in the "old" areas....
I am not sure where to start looking for this.....in some ways it sounds like a routing issue...but the routes did not change....so I think it might be a configuration issue.... but which configuration file....each area has its own configuration file and then we have the master configuration file....
Has anyone see a problem like this?
You can use RouteDebugger to debug your routes.
I found a partial answer....At the same time that I changed the areas I renamed the project.... When I created the new areas they got the namespace created using the OLD project name....and I did not notice the namespace was wrong.... The clue to this was the fact that path completions were not working....I should have looked more closely at this....
Now the big question, and the reason that I am marking this as the answer is....where does the project name get retained in asp.net mvc..... I have looked in the web.config and I have done a global search for the old project name ..... Any clues where to change this???

MVC4 Portable Areas?

Does MVC4 remove the MVCContrib requirement to achieve portable areas? Or is that still required?
I gave it a shot w/o MVCContrib and unfortunately I'm stuck with a typical "The view 'Index' or its master was not found or no view engine supports the searched locations." exception.
The list of searched locations includes "~/Areas/Inbox/Views/Default/Index.cshtml" which is technically correct, but it's just not finding the view.
Some explanation:
I have a main MVC4 application and a "plugin" (if you will) MVC4 app that contains an area called Inbox with a controller and view named Default. I reference this plugin app in the main app and I can hit a breakpoint in DefaultController's Index method where the View is returned - so I know the main app is engaging the plugin app and routing the requests to the proper controller and all that. When not running, if I cursor over the return View() statement in DefaultController the balloon shows the desired view, it's just not found at runtime.
Has anyone encountered this? I'm sure it's something really simple and a stupid oversight on my part, but after hours of trying, I can't find a solution. Thanks in advance!
MvcContrib is not a part of MVC, so no. MVC4 does not include Portable Areas. MvcContrib is not like MvcFutures where it's likely that at some point the code will be rolled into the main project. This is code that is contributed by third parties.
For each view, edit the Properties and set the Build Action to Embedded Resource.

ASP.NET MVC 3 RC and custom ViewEngine to allow for externally loaded Views

I'm playing around a little with dividing up a MVC-site into several assemblies (ran into some issues earlier).
Now I have almost everything working, got the main MVC project that loads in any external assemblies it can find. The external assemblies are basically external areas. When I had it copy the Views and web.config to the main-sites Areas-folder everything worked just fine. Now, that folder will most likely start to get a little bloated after a while, so I thought I'd try to add in the Views as resources in the area-assembly instead, see how that worked.
Created my own VirtualPathProvider and my own VirtualFile, registered them with the HostingEnvironment thinking all was well. Turns out it only uses the VirtualPathProvider added to the HostingEnvironment at the first load, not by the following View-loads by the ViewEngine.. Ok fine, found a few examples of how you could get around this by implementing your own ViewEngine to use your own VPP. But yeah, this doesn't seem to be a workable solution for MVC 3..
As it turns out, neither RazorViewEngine nor WebFormViewEngine implement two of the "key-functions" it seems, FileExists and IsValidPath. These are inherited from BuildManagerViewEngine, and you know what? These methods are marked as sealed..
Anyone who has tried this with MVC 3 and perhaps could nudge me in the right direction? I've been staring at the MVC 3 source now for quite a while but I just can't see any way of doing this..
Now I feel a little stupid, it seems I loaded the VPP too late.. Had it in Application_Start, but when I moved it to my PreApplicationStartMethod instead, it was used by the ViewEngine. (So no implementation of ViewEngine seems to be needed, wey!)
Problem now is that when I try to get to a View that's stored as a resource, I get to download it instead of having it rendered.. But that's something different from this so!

Changing ASP.NET MVC default folder structure

Is it possible to change around the folder organization to the following and still have MVC work.
P1
Controllers
Models
Views
P2
Controllers
Models
Views
etc..
This looks a lot like the new feature area's which is available in MVC 2 though it is currently in preview and will be release with VS 2010.
If you want to do it yourself without using areas then check out this article on view engines
as said before, the Areas feature is what you are looking for.
If you are using vs2010, then although you have MVC2, you don't have the tools for creating the areas - these are only available on vs 2008, when you install the MVC2 rc
to make it happen follow the instructions at the following link: http://msdn.microsoft.com/en-us/library/ee671793%28VS.100%29.aspx
as you can see the menu options are missing so:
download the example project from there.
build the directory structure at your solution according to the example
change the AreaRegistration.cs to match your area name
add AreaRegistration.RegisterAllAreas(); at the RegisterRoutes function at the global.asax, right after the IgnoreRoute
NOTE: the namespaces shuold contain .Areas.
for More explanations search at stackoverflow for asp-net-mvc-2-beta-single-project-area-registration-getting-http-404 (since this is the first time i post an answer - SO doesn't let me append more then 1 link, go fugure..)
Hope this helps
Should be doable, I think the default folder structure is just a suggestion. I've seen before in some documentation that larger projects would likely be split up differently, possibly even among multiple assemblies.
The only thing I would think would cause some trouble would be the views. Since controller actions are mapped to them only by file name. I know there's some way to change them, but I have not had to do so yet.
You can create your own viewengine to solve the paths. That sounds like a very strange idea, but the ViewEngine class is actually responsible for 2 things: locating a view and rendering a view to the httpresponse. The thing you have to change is the locating part, you can just inherit the default aspxviewengine and change the view locating part.

Resources