- Getting Started
- Upgrade V2 to V3
- Operational Summary
- Automatic Data Updates
- Web Applications
- trie matching
- Image Optimiser
- Passing Properties To Client Side
- Client Side Overrides
- User Performance Monitoring
- Offline Applications
- Accessing Metadata
- SQL Server
- IIS Modification
- Log Troubleshooting
- Native Code
- Examples And Questions
ASP.NET MVC 4 works well with the Detector as different views can be used for different kinds of devices while maintaining the same logic in the controller. This guide details how to create views that will be used according to different device conditions. You should be familiar with MVC routing to make full use of this article; see this guide from ASP.NET a quick overview on MVC routing .
First install the Detector using Nuget. You will not need the mobile folder the Detector adds, or the redirect section in the 51Degrees.config file.They should be deleted.
You now need to create your views. Their name should include an identifier for their purpose before the extension, i.e: Index.android.cshtml.
Your views should be something like this. Notice they are all in the same folder, so will have the same controller, and have the same name (Index), so will all have the same url. The above screen shot shows views created for Android, iPhone and generic mobile.
Important Note : 'HardwareModel' and 'PlatformName' properties used in this example will only work with Enterprise or Premium data files. For Lite data file please use the ' IsMobile ' property. For a full list of properties and data files they appear in please see the Property Dictionary page.
To set the conditions for which view is used some code needs to go into the Application_Start event. This event should already exist in global.asax. It is in this method that you'll need to register all the views you have and under what conditions and the priority they should be used in. For each view you will need DefaultDisplayMode:
A DefaultDisplayMode features a name (iphone in this case) and a condition. The name is used to identify the view. You will also need to include the System.Web.WebPages namespace.
The full global.asax should something like this:
Note that the order the DisplayModes are given are important. They are processed in order until a match is found. Therefore is is safe to include a generic mobile mode as long as it is at the last DisplayMode given. Also note that the properties used here are for premium data.