1

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

Zac Seth
  • 2,742
  • 5
  • 37
  • 56
  • I agree with you that it indicates you're somehow pointing to MVC 1. What did you do to verify you're pointing to MVC 2? – Steve Michelotti Sep 29 '10 at 05:36
  • @steve, the 'ViewlocationsFormats' are defined as the OP describes in MVC 2 as well. @Zac - have you registered your area routes? – Ahmad Sep 29 '10 at 09:04
  • @Zac - are you sure about the 'should be' list of locations? – Ahmad Sep 29 '10 at 09:15
  • @Steve - we opened all of the project files in a text editor and checked for the System.Web.Mvc reference - all of them were for 2.0.0.0 – Zac Seth Sep 29 '10 at 21:22
  • @Ahmad - Yes, we've registered the Area routes - the controller actions are being invoked so there is no issue as to routing. The problem seems to be related to the view engine component. As for the 'should be' list, I'm not 100% certain that's how it should be but it is close. Cheers – Zac Seth Sep 29 '10 at 21:25
  • @Zac - just noticed, your question title refers to the 'partial views'. Does this work for normal views or is the issue only when using RenderPartial()? – Ahmad Sep 30 '10 at 04:48
  • It's the same in both cases - we've tried setting up standalone test views with minimal/no functionality and we've tried using Html.RenderAction(...) but neither work. – Zac Seth Oct 03 '10 at 23:03

1 Answers1

2

What things could we look at that might help us resolve this issue?

  1. Make sure Area Routes are Registered AreaRegistration.RegisterAllAreas(); are registered first. Area routes need to be registered as well.
  2. Make sure generated URL links have the area name included as one of the arguments when using ActionLink and other related URL helpers
  3. Sometimes just delete and re-add the Area from scratch. Sounds silly, but it works.
  4. The related SO question on the left hand side of this page may help. I have linked one I think may be of value
Community
  • 1
  • 1
Ahmad
  • 22,657
  • 9
  • 52
  • 84
  • Thanks for the response Ahmad, unfortunately, none of these have helped. As I mentioned in a comment on the question, above, the problem is not related to routes - it's an issue with the WebFormViewModel as far as I can tell. We've reproduced the issue with a couple of computers/devs so adding and then removing areas hasn't helped. – Zac Seth Sep 29 '10 at 21:56
  • @zak - what's a WebFormViewModel? – Ahmad Oct 06 '10 at 15:13