My initial experience with ASP.NET MVC3 and Razor

A couple of weeks ago I was asked to develop a mobile application with data access in ASP.NET.

Naturally, I did a bit of research, tried out a few things, and finally came to the conclusion that .NET framework 4.0 was the best choice.

So I got down straight to development, using Jquery Mobile Framework, ASP.NET with .NET 4.0,  MVC3, ADO.NET Entity Framework 4.1, and ASPX (web forms).

It was easy enough to set up, but when it came down to implementing user controls, I found it a nightmare. Passing parameters to the user control whilst using a MultiView was giving me a headache.

The issue here is that web forms are not naturally set up to work via AJAX calls, and Jquery Mobile Framework relies entirely on AJAX calls. So I decided to try out the Razor layout engine instead of web forms.

I had no experience using the Razor layout engine, but after a couple of hours, I found it delicious to use. I could code up pages much faster than in web forms. And the integration with controllers and models in the MVC3 framework was just, natural, it all fit into place beautifully.

Naturally, I found a few issues learning the basics of the MVC3 framework, forms authentication, the Razor layout engine, and accessing data from a database. Tutorials seemed to be all over the place, but I came across a few good ones which I will share with you.

If you are getting started with MVC3 + Razor + Data access (using DBContext in MVC3), follow these tutorials, and you’ll be a ‘pro’ in a couple of days (providing you have enough experience).

Razor Layout Engine:

Learn the basics of the Razor layout syntax:

http://msdn.microsoft.com/en-us/gg618477

Learn how “sections” work in Razor:

http://weblogs.asp.net/scottgu/archive/2010/12/30/asp-net-mvc-3-layouts-and-sections-with-razor.aspx

Learn how to implement partial views in Razor (which can be used as ‘user controls’):

http://rachelappel.com/razor/partial-views-in-asp-net-mvc-3-w-the-razor-view-engine/

MVC3:

Learn how a basic MVC3 application works in .NET:

http://www.asp.net/mvc/tutorials/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript

Learn how to integrate data access (database first) using MVC3 and EF 4.1:

http://msdn.microsoft.com/en-us/data/gg685489

(If you want to create models, but use a MSSQL database that is not on your machine, and you don’t want to have it in the App_Data folder, just follow the steps, then delete the database from the app_data folder, and change the data source in the web.config to point to the correct location).

Writing your own queries to access the database instead of relying solely on those from the model:

http://blogs.msdn.com/b/adonet/archive/2011/02/04/using-dbcontext-in-ef-feature-ctp5-part-10-raw-sql-queries.aspx

So that’s it for now, I thought it would be good to have a central location for these tutorials as they served me well whilst I learned the basics of MVC3 + EF4.1 + Razor, so I hope they are useful to you as well.

If you have any queries, please let me know in the comment section below.

FF4 vs IE9 vs Chrome10

IE vs Chrome VS FFBefore you go all “Oh no! Not another review on the latest browsers!” on me, I state that I have been on the net and looked at reviews and comparisons of the latest browsers, and I am somewhat dissatisfied.

There are quite a few comparisons of IE9 vs FF and Chrome, but most of them seem to be from October 2010, using an RC instead of the final release, including Opera, or excluding one of these three browsers I’m reviewing.

Let me state the purpose of this post bluntly: This is not a review, nor am I meddling with V8 or Acid3 tests, we all know you can use Google to find the results straight away. I want to give my personal perspective on how well the browsers perform in real-life tasks.

After using all three browsers for about a week and a half, each one with all my regular tabs open (7 permanent, 1-7 additional), this is what I have found thus far:

Chrome 10: Fast as always, speedy start-up, no crashes in the time period (except for Flash plugin, twice). Chrome supposedly integrated GPU acceleration since build 7, so I ran the IE Fish Tank test made by Microsoft, and it reports approx. 20FPS, which is low, however, the animation looked OK to me anyway. RAM used was quite high, but performance did not drop even when I had about 14-15 tabs open (including Youtube, Grooveshark, Gmail, Docs, Hootsuite, amongst other heavy web applications). My rating: 9/10 for day-to-day use, 6/10 for animation-loaded sites.

Firefox 4: Sleek new interface, speedy when few tabs are loaded, sluggish when using over 10 tabs (specially in Google Calendar), no crashes in time period, GPU integration seems good, Fishtank’s average FPS was just below the maximum (over 50FPS) which means Firefox has done a great job integrating GPU acceleration into the browser. RAM was lower than Chrome, but performance did drop when I opened many tabs. My rating: 7/10 for day-to-day use, 9/10 for animation-loaded sites.

Internet Explorer 9: Installation time for Windows 7 64-bit version was longer than it’s counterparts (approx. 7+ minutes including necessary updates) and it asked me for a bloody Windows restart (typical of Microsoft). The browser that claims “fast is now beautiful” is actually quite fast to start up, but I’d leave “beautiful” as a perspective issue, though I must say it looks much better than IE6, 7 and 8 combined. Opening tabs is much faster than it’s predecesors. I don’t like the fact you can’t “pin” tabs like you can in FF and Chrome. GPU acceleration has given this browser a big boost in overall speed. When you open a new tab it displays useful data, similar to Chrome, which Firefox does not display. Google Calendar runs faster than in Firefox, but a bit slower than in Chrome. The overall speed remains good even with 10+ tabs open. I don’t like the feature it has of opening tabs next to the address bar by default, though that can be changed, obviously. I prefer the all-in-one bar to the dual-bar in Firefox. RAM usage was significantly lower than in Firefox, by about 40%. I didn’t like the fact that it didn’t ask me which search engine it should use by default. Fishtank’s FPS were even higher than in Firefox. My rating: 8/10 for day-to-day use, 10/10 for animation-loaded sites.

As a brief summary, my ratings are as follows: Chrome > IE9 > Firefox 4 > Firefox 3 > Firefox 2 > Firefox 1 > All other versions of IE

If you like this post, don’t forget to share (using the buttons below) and subscribe at lemiffe.com

Microsoft ahead of the game with IE9?

Browser wars are back!

Microsoft has just released IE9. Now, we were aware of a new look, impressive speed, and other impressive aspects of this revamped model of IE9 for quite a while now… But is this a game changer?

Check out the promotional video below:

I’ve not had a chance to give it a go yet. I am an avid fan of Google Chrome, it just never fails me. Before this I used to be a Firefox supporter. I left Firefox because it just seemed to drag the system’s performance down. I’ve not used Internet Explorer for years now, as I experience no problems on any page with Chrome.

However, I’m curious to the impact Internet Explorer 9 will have in the worldwide browser usage. Hopefully it will get more users off IE6 for good.

What are your thoughts on IE9? Have you tried it out? Would you be willing to try it out? What do you expect of it?

Is Ubuntu the right option for you?

When you ask a Linux fan “I am buying a new computer, should I get Ubuntu or Windows 7?”, they usually vouch for Ubuntu straight away, many times without considering the actual needs and limits of the user. They usually recur to a slur similar to the following: “Ubuntu is like Windows but much safer, plus you can open Microsoft Office documents, you have Firefox, it is much harder for you to get infected by a virus, and in many ways is easier to use than Windows”.

If that doesn’t convince him/her, they might end up with the classical “you can get cool effects that look like Mac OS X by installing Compiz”.

However, in my personal experience, Ubuntu is not for everyone. I have recommended it before (As part of the Dell-Ubuntu offering), I have heard other people recommend it to others, and I witnessed the Ubuntu-boom when netbooks gained popularity; The return rates were much higher for Ubuntu netbooks as users generally dived in because of the price tag not knowing that what they were receiving was essentially not Windows.

That said, Ubuntu is a great distribution of Linux. I’m sure most hardcore Linux fans would debate me on that issue, however, in terms of usability and getting things done fast, I regard Ubuntu as top of the pack right now.

So I have developed a little insight into the main features of Ubuntu to help newcomers choose whether they want to install Ubuntu or hang on to Windows or Mac OS:

Viruses

There is no escape from viruses, on any single operating system, however, in Ubuntu it’s much more difficult to get infected by a virus as the system has directory-based, user-based and computer-based security instead of only user-based security found in standard versions of Windows. This means that a virus could only potentially wreck the directory where it has installed itself in Linux, while under Windows it can wreck havoc in any directory it chooses.

Most system file changes under Linux require administrator password which gives you extra control over what is going on with your system.

Internet

It is basically the same thing as a Windows PC with the exception of not being tied down to Internet Explorer. Firefox comes pre-installed on Ubuntu, but you can install Chromium (Google Chrome for other OSes) and it is pretty stable nowadays. Flash/audio usually works out the box, unless you have an old computer with unsupported hardware. There are quite a few other browsers you can install from the software installer with just a couple of clicks.

Audio

Ubuntu comes with a default audio player called Rythmbox, I am not very fond of it as I am used to iTunes, but it plays your music, has playlists, visualisations, and common functions found in most audio players. One of the problems I have encountered with this audio player is that it verifies your whole playlist every time you open the program, so if you have a massive playlist it may take a couple of minutes to verify each file still exists.

Rhythmbox, banshee and guayadeque are really good open source audio player equivalents and the first 2 allow iPod syncing easily. I tried syncing my iPod Touch a year or two ago without success and found out that there was an encryption system on the iPod Touch which made it hard to sync with anything other than iTunes. Apparently I have been proved wrong as I’ve been told by several people on Google Buzz; You can supposedly sync to an iPod Touch nowadays.

There are several recording programs which I have found easy to use, however, I haven’t found any professional open-source programs that can substitute great sequencers that run in Windows such as Cool Edit Pro, Live, etc.

Video

Comes with necessary codecs for standard video, and if you want to play AVIs and WMVs you can always get the necessary codecs for free. The OS tells you which ones you may need when you try to play an unsupported video. This means: No messing about on-line trying to find codecs hour after hour through spam and adware filled websites.

Documents

Well, obviously OpenOffice.org is the way to go with this one. OOo is pre-installed with Ubuntu. I don’t love OOo but it is compatible with MS Office 2003/2007 and gets the job done. It lacks a few features available in MS Office 2007, and doesn’t have a great look-and-feel but hopefully some day the guys will develop a more competitive version.

Graphics Design & Editing

GIMP is a complete graphics editing suite, it can’t compete against Adobe PhotoShop in any way, but it gets the job done, however, it does have a bit of a learning curve if you are used to Photoshops GUI. I would compare it to Paint.Net on Windows. It has layers support and a full set of tools but the interface is not that intuitive.

Programming in PHP

If you are a PHP programmer you will find LAMP has everything you need to get started with about 3 clicks.

Programming in .NET

If you are a .NET programmer you might find MonoDevelop quite useful. You can develop using C# code mostly compatible with Windows. I haven’t tried out Mono on Ubuntu yet as I generally use my Windows box to code .NET but I have heard it is quite good nowadays.

Conclusion

There’s an online community of help and support if you have any issues: Forums on the official website, lots of other independent forums, an IRC channel (or various should I say) on #ubuntu on Freenode: All of it completely free.

Go ahead and try the Ubuntu Live CD before installing it… You can download it at the official website, burn it onto a CD and try it out before installing anything.

Thanks to Mark Skinner who resolved my questions about iPod Touch syncing on Rythmbox.

On the usefulness of tablet computers

I recently read an interesting article on TechCrunch which talks about the 6 or so operating systems geared towards tablets which will soon have to face a battle for who gains the most popularity in the limited market of tablet PCs.

Linda Lawrey posted this article on her Google Buzz which sparked a discussion about who might be coming out as winner, but it also generated a conversation about why anyone would want a tablet in the first place. I think 3+ million iPad owners would have something to add to that conversation, however, my post is not about that.

I personally believe tablets are useful for certain things today: While not exactly great for use on-the-go such as mobile phones they are useful as a replacement for net-books, say, for use while having a coffee at Starbucks, for taking notes while at meetings, or as a bed-side computer to check mail and browse the web before bed. But my thoughts about their usefulness are centred on the future: Internet-powered centralised intelligent home & office devices.

I can see them integrated to each room in a house, possibly on the wall, where one can quickly browse their calendar, program their alarm, control the lights of the house, communicate with the house’s security system, view CCTV video from other rooms and program DVR recording, control other digital devices from their room, etc.

Imagine: You’re going to bed so you go to your wall and program the alarm clock for 8 AM, you also program your children’s alarm clock for 7:30 AM, activate the home security system, and set up chilled-out relaxing music for the bedrooms in the house. You also program the device to start up the radiators at 6:00 AM and the hot water at the same time. At the same time you set up the A/C to maintain a certain ideal room temperature during the night. John, your kid, doesn’t like the music so he gets up and sets his own device to mute for his room. You wake up to the sound of music, increasing gradually in volume in each room, as a start to a great new day.

You might have a party that evening and you are having a discussion about a certain word definition, or the location of a country, so you get up, unplug the tablet from the wall, and perform a search on Wikipedia, bringing the tablet to the table and sorting out the discussion in moments.

In the office, you create a powerpoint presentation with interactive graphs and cool pictures on your PC. You store it on the local network, pop in to the conference room, take a tablet down from the wall, then you can discuss the points and make changes directly on the tablet, making the meeting a more productive one than the usual guy talking in front of a projector while people take notes. Not good enough? Connect a pico-projector to it, then you can have your boring meeting with the capability of making changes or taking meeting notes directly on the tablet, which makes the use of paper basically redundant.

So how useful do you believe they are? Useful enough right now? Or more useful in the near future?