This project is read-only.


Topics: ASP.NET MVC, ASP.NET Web Pages
May 12, 2012 at 12:04 PM
Edited May 12, 2012 at 12:57 PM

I just started looking into DisplayModes feature of ASP.NET MVC 4. I've looked at it in the preview version but it has changed a lot in the beta as far as I can tell.

The registery point for DispalyModes is now System.Web.WebPages.DisplayModeProvider.Instance.Modes property which is type of IList<IDisplayMode>. When I look into this collection, there are two DisplayModes by default and both of them are type of System.Web.WebPages.DefaultDisplayMode. The one of them is for mobile whose index is 0. The second one is empty.

Based on that, if I do the following inside the Application_Start:


I get the so-called ASP.NET MVC 404:

System.InvalidOperationException: The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:


and this error message lies because ~/Views/Home/Index.cshtml is present. As for my questions:

  1. Is this an expected behavior?
  2. Is the DisplayMode I've removed required for Razor views to function properly? In other words, Is System.Web.Mvc.ViewResult.FindView method directly bound to DisplayModes?
  3. Is DispalyModes feature now part of System.Web.WebPages?

I tried to make sense from the latest source code but couldn't get it right for sure. Also, that would be great if you can point out a good resource (blog post, MSDN article, etc.) (if there is one of course) which explains the latest DisplayModes behaviors.

May 12, 2012 at 5:37 PM
Yes, yes, and yes. :)
May 12, 2012 at 6:08 PM
Edited May 12, 2012 at 6:10 PM

Very direct answers :) but there is a fact here that the error message lies. Is that a bug in beta? 

Also, does that mean DisplayModes cannot be used for other view engines?

May 13, 2012 at 4:02 AM
Open a bug. :) We'll see what's going on.
May 13, 2012 at 11:51 PM

Thanks Brad!