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.

The increasing level of connectivity between Social Sites

A few years ago I dreamt of being able to have all this connectivity, lets say, things being published here, automatically-published there, and elsewhere. I knew we were getting there, as I have been configuring my services for the past few months, but I didn’t know we are so advanced.

If I made a rundown or a graph explaining the connectivity between social media sites I currently have, it would grow too large, or the connections would not exactly be easy to draw. * Update: Well I’ve decided to draw it anyway:

My Network Map

My Network Map

For instance: My Youtube is posting to facebook, google reader, twitter and two of my blogs. One of those blogs is lemiffe.com which when receiving a post will alert ping.fm which will then release a post of my new blog post to facebook, twitter, my blog at blogger, myspace, google talk’s status, and quite a few other sites.

Now, the only problem I currently see is the level of redundancy. Sites talked to other sites, which in turn talk to other sites, so whenever these sites provide much more connectivity to other services we might end up in a cyclic-post system in which one service posts to the other which in turn posts back to the first one initiating a never-ending cycle in which the user would have to stop one or the other service manually.

I really believe more insight should be applied, like, verifying the other sites connectivity and checking it will not repost to a site the first site has already posted to. This can be done via pure XML transactions between both sites, I mean, thats what web services are for, right?

Another thought I came up with is a Centralised User Account Service, which deals with the connectivity between users of different sites. Lets say: Gravatar meets facebook and ping.fm. All the services first verify the users information on the Centralised service, then they verify which permissions the user has applied concerning posting, which pages must the service send the new update, video or blog message to, and negotiate it only with the Centralised site, which will in turn send off the appropriate XML for all other “connected” sites.

It’s just a thought, Security-wise I am not sure where this would lead to as very tight security would have to be placed. Gaining access to the account of a user at the Centralised Site would be, well, Armageddon for that user. So probably a tighter security would have to be placed, with 128 big encription, SSL sockets, MD-6, who knows what else, but it’s just a thought anyway.

New Design

I was told already by 2 people that my new design looks terrible, so I’ll probably be fiddling around with the graphics and stuff on the page for the following weeks. Any comments and critique is accepted. Thank you and excuse me for the poor visual performance.

Stop Using Excessive Flash!

When building your website, I’d suggest to ease out on flash. Maybe in a few years, when regular bandwidth is at 6MBPS and higher it would be acceptable, but today most users still have 1MBPS and lower. It takes too long to load flash sites built 100% with flash.

Example: http://www.microsoft.com/forefront/easyeasier/index.htm#intro

Please reconsider building a website 100% with flash, it’s much better to opt for a nice flash intro, and use it in various parts, sidebars, etc. You optimize speed and experience that way. Just a tip ;)