by rcats on December 19, 2010
I’ve been experimenting with some of the CTP’s and beta products Microsoft has been releasing over the past couple of months. There’s some really good stuff available to us today, like MVC3, Razor, CodeFirst Entity framework, @helper libraries, NuGet and Visual Studio Extensions that you can use to quickly build nice websites. Also, I’ve come to love Ninject and introduce the library to you if you aren’t familiar with it yet. IOC is something you should know. I’ll be doing some video blogs and tutorials here.
First up is the Facebook helper library that’s being released. You can use the facebook helper classes to easily add a ‘like’ button or comment box to your webpage, and enable users to post this comment to their wall.
First step is installing the helper package using Visual Studio library package manager (references > right click > add package library reference).
This adds a folder facebook to your project, some helper files (read this for more options and functionality!) and a facebook.cshtml file in your app code folder. In this file you will find the available helper functions which are documented well. Now it’s very easy to use these methods. To add a like button for instance, just add this line to your view:
Or add the comment box.
@Facebook.GetInitializationScripts() @Facebook.Comments() @RenderBody()
Out of the box, there’s a problem because the facebook helper class uses classes in the WebMatrix namespace. You have to include WebMatrix.Data and WebMatrix.WebData as references in your project. Also, make your you copy them locally using the reference property dialog or just manually add them to the bin folder, otherwise the facebook.cshtml file will generate a compile error when running the site (this is not caught design time).
Just a quick post to start off with, more to come!
ps: it’s also worth having a look at the microsoft.web.helpers package and namespace. Here’s what you get out of the box