1
Vote

MVC SiteMap does not see existing Controller

description

I couldn’t get the MVC SiteMap provider to work with existing project that already has controllers and views. However, I had no problem with MVC SiteMap when I created a new project. At first I couldn’t figure out why because it looked pretty straight forward. I found that MVC SiteMap couldn’t see existing controllers (even though you specify the controller in Mvc.sitemap). See below to replicate issue. I can’t figure out why this would be an issue. One would think that it is reading the site wireframe through Mvc.sitemap.

Windows 7, 64-bit
Visual Studio Professional 2010
MVC3, .NET Framework 4.0

How to replicate issue:
  1. Copy an existing controller into the Controller folder
  2. In Visual Studio, right-click on Controllers folder and Add > Existing Item > select your controller
  3. Create a View for your controller, ie Index.cshtml
  4. Add new controller to Mvc.sitemap
  5. Run the application. You will not see the new view.
  6. In Visual Studio, right-click on Controllers folder and Add > Controller
  7. Create a View for your controller, ie Index.cshtml
  8. Add new controller to Mvc.sitemap
  9. Run the application. You will see the new view.
If you create the controller through Visual Studio instead of “Add Existing Item”, you will not have any issue. Why would this matter?

comments