Adding a Faceboook ’Like’ button to an MVC 3 Razor applicationAdd to My Brief

Craig Lovegrove | 15/08/2011

Adding the Like feature to a website enables users to quickly and easily share a page they like onto their profile on Facebook. This is massively beneficial for a company as facebook is a global advertising agency; if you manage to get one user to share a link to your site it will instantly be advertised to all of their friends around the world.

 

Facebook requires the site to do 3 things before it will allow you to add the Like button to your website:

 

  • Add a reference to the Facebook Javascript componant in the head (hosted by facebook)
  • Add an empty div tag with the id 'fb-root'
  • Add an tag containing all the attributes of the button

 

Adding the following code to the _Layout.cshtml file will bring up a nice Facebook Like button on your page:

(Within the head tags:)

(Within the body tags:)

The link will look something like this: 

 

 

A full list of attritbutes and view styles can be found at the official facebook Like Button page

 

tags: Web DevelopmentFacebook

Interested in learning more?

Wiliam is a leading supplier of web solutions and can provide expert advice to assist your business or organisation online.

Make enquiry   Request quotation

Comments

Share this page

Print this page Email this page to a friend Bookmark and Share

No Brief added yet.

My Brief results-driven approach emphasises a commitment to our clients needs through strategic analysis and best-practice.

Add to My Brief

Click on this icon to save item into My Brief. Retrieve, email and print

Drag & Drop

Drag & drop any iten with this icon into My Brief. Retrieve, email and print

Search Blogs