Aug 13, 2013

Display Modes in ASP.Net MVC 4

Display Modes in ASP.Net MVC 4

Display modes is a new concept in ASP.Net MVC 4. The new Display Modes feature lets an application select views depending on the browser that's making the request. For example, if a desktop browser requests the Home page, the application might use the Views\Home\Index.cshtml template. If a mobile browser requests the Home page, the application might return the Views\Home\Index.mobile.cshtml template.

From a more technical perspective, a display mode in ASP.NET MVC is represented by the IDisplayMode interface and subsequently the DefaultDisplayMode class. The MVC framework uses the DefaultDisplayMode class to represent both desktop and mobile browsers.

There are two ways to create a custom display mode. The first way is to instantiate the DefaultDisplayMode class and set the ContextCondition property. The second way is to create a class that inherits from the DefaultDisplayMode class and set the ContextCondition property in the constructor. 

Applications using DisplayModeProvider should install the Fixed DisplayModes NuGet package.


No comments:

Post a Comment