Display modes are new to ASP.NET MVC 4. They allow us to target specific devices based on some matching criteria contained in an HttpContext
, typically a user-agent string. Upon a match, the display mode identifies the suffix appended to any view specific to the device. It is actually this technology underlying the .Mobile
suffix we just learned about.
Display modes are represented by an implementation of the IDisplayMode
interface defined in System.Web.WebPages
. At application startup, implementations of IDisplayMode
can be registered with the current DisplayModeProvider
.
We will be creating and registering an instance of IDisplayMode
for the Asus Nexus 7. Our new display mode will use a suffix of nexus7
for any Asus Nexus 7 specific views. This means that the layout file _Layout.nexus7.cshtml
will be used for any request to our site made by an Asus Nexus 7.