Switchable desktop and mobile view in MVC projects

Scott made an awesome article about implementing a switchable desktop and mobile view in your MVC projects.

Additional hints:

The solution above provided doesn’t work for android phones. Add this code in your Global.asax to get it done.

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile")
ContextCondition = ctx => ctx.GetOverriddenUserAgent().Contains("iPhone") || ctx.GetOverriddenUserAgent().Contains("Windows Phone OS") || ctx.GetOverriddenUserAgent().Contains("Android")

How to use AJAX in .NET MVC projects

When developing Web Projects one point you should always keep in mind is this: A great web project makes the user feel, that there is no web. You created a good user-experience when they just forget that they are working in a browser.

One way to achive that, is using AJAX as often as possible

Why? Because Page Load is a user experience killer. The complete page refreshes which is awful in UI and even worse for us programmers, cause we have to store user selections in our viewdata and so on. Very bad. Using ajax and refreshing only parts of your site makes the user feel comfortable and is actually easier for us programmers.

Code in your javascript file (I recommend to generate extra javascript files, to keep your views clean)

function drawChart(month, year) {
type: 'POST',
data: { param1: month, param2: year },
dataType: 'json',
success: function (data) {
//Make something with your data

Then in your Controller your functions should look like this

public JsonResult GetChartData(int month = 0, int year = 0)
//Generate or get your data from db
return Json(data);

Thats all. Easy and powerful.

Now, one last thing is your UI behavior. When you gather your data from a database you should display a loading panel or something like that, so your users know what’s going on. A great way to do this, is using the BlockUI Plugin for jQuery

Here you can see some demo cases:


And here is some example code (As mentioned above I recommend to extract all javascript and jquery code in separate files to keep your views clean!)


Easy to use and looks very great. We’re in developers heaven 😉

Start with .NET MVC 4

.NET MVC is the first Microsoft technology which is really well documented and with practical samples. Beside that i like the architecture which is really simple but powerful. I never want to write a .NET ASP Project again.

Here you find all what you need to start:


I highly recommend the Music Store Tutorial: http://www.asp.net/mvc/tutorials/mvc-music-store

Well done, Microsoft! (I don’t‘ say that, that much :))