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:


Learn how “sections” work in Razor:


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



Learn how a basic MVC3 application works in .NET:


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


(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:


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.

9 thoughts to “My initial experience with ASP.NET MVC3 and Razor

  • Erick Alvarez

    Dudeee, desde cuando que tenias que haberle entrado al MVC, se sopla de todas maneras y formas al webforms.

    Una vez que le entras ya no quieres ni necesitas regresarte, se siente cómo todo tiene su lugar y en general te da la sensación de que está bien hecho, obvio que si empiezas a llenar de mugrero tus views y controllers ps ni que hacer :P.

    Hace 2 semanas también acabo de sacar la versión movil de una app del trabajo, igual con jquery mobile y si sale muy rápido, lo probé actualizando el proyecto a que usara mvc4 para lo de los views con extensión .mobile.cshtml pero después de un rato aveces me daba problemillas (con eso que aún es un developer preview) y preferí regresarme y ya no he tenido broncas, si quieres checarlo está en http://www.medicbook.com.mx, si entras desde un mobile te redirecciona, si entras desde desktop agregale un /mobile/ al ultimo para verlo.

    Cualquier cosa referente a todo este pex pues ya sabes 😉


    • lemiffe

      Bastante chido tu sitio, pero no encontre ningun dentista cerca de mi codigo postal en Mty!!! Hahahahaha. Oh well…

  • [email protected]

    una y otra vez cuanto sea necesario , hay que probar y probar .

  • http://dream-analysis.org

    Some truly interesting information, well written and broadly speaking user genial.

  • Rajeev Nair

    Thanks so much for the article. Informative and well written, for whomever starting to use MVC3/Razor apps.

  • Neal

    Why isnt there a free tool like spring roo for CRUD development in .NET world?
    Or is there?
    I want to scaffold a mysql db

  • Mehregan

    Thank you for this helpful post

  • douche exterieure pour piscine meilleur prix

    Heya i am for the first time here. I found this board and I find It really useful & it helped me out much. I hope to give something back and help others like you helped me.

  • Alejandro

    En lo personal prefiero el ASP.NET

Comments are closed.