DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Using ASP.NET Web Pages Helpers in ASP.NET MVC

Using ASP.NET Web Pages Helpers in ASP.NET MVC

Imran Baloch user avatar by
Imran Baloch
·
Apr. 03, 11 · News
Like (0)
Save
Tweet
Share
7.21K Views

Join the DZone community and get the full member experience.

Join For Free
Introduction:

          ASP.NET MVC 3 includes some helper methods of ASP.NET Web Pages technology that are used for common functionality. These helper methods includes: Chart, Crypto, WebGrid, WebImage and WebMail. For details of these helper methods, please see ASP.NET MVC 3 Beta Release Notes. However there are some other helper methods present in ASP.NET Web Pages and may also be useful for you like Google Analytic, Bing Search, Twitter Profile, Facebook Like etc. For details of all ASP.NET Web Pages helper methods, please see ASP.NET API Quick Reference. In this article, I will show you how to use some of these helper methods in ASP.NET MVC. 

 

 Description:

          Before starting this article, I would like to mention that the technique in this article will also work in ASP.NET MVC 2 and Web Forms but some helpers like Facebook.LikeButton is dependent upon ASP.NET Web Pages due to which some helpers will not work in ASP.NET MVC 2 and Web Forms but work in ASP.NET MVC 3. So let's create an ASP.NET MVC 3 application. After creating the application, just add a reference of Microsoft.Web.Helpers.dll. This assembly will be found in WebMatrix directory when you install WebMatrix. If you don't have WebMatrix installed then don't worry. This assembly is included in the downloadable project.

 UPDATE: 

          Please note that the above project was built with ASP.NET MVC 3 Beta which includes the old version of Microsoft.Web.Helpers.dll. So if you are using ASP.NET MVC RC or any other new version then get the new version of  Microsoft.Web.Helpers.dll by right clicking on solution explorer then Add Library Package Reference then search microsoft-web-helpers. In this new version Facebook class is no longer available. Also the new version uses HttpContext.Current instead of WebPageContext.Current.HttpContext which was used in previous version. 

 

          

 

 

          Then just open Index View and add the following lines,

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
02
03 <%@ Import Namespace="Microsoft.Web.Helpers" %>
04 <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
05 Home Page
06 </asp:Content>
07 <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
08 <table>
09 <tr valign="top">
10 <td>
11 <%=Twitter.Profile("scottgu")%>
12 </td>
13 <td>
14 <%=Twitter.Search("ASP.NET MVC")%>
15 </td>
16 </tr>
17 <tr valign="top">
18 <td>
19 <%=Facebook.LikeButton("http://weblogs.asp.net/imranbaloch")%>
20 </td>
21 <td>
22 <%= LinkShare.GetHtml("Imran Baloch's Blog", "http://weblogs.asp.net/imranbaloch")%>
23 </td>
24 </tr>
25 </table>
26 </asp:Content>


First of all I have imported the namespace Microsoft.Web.Helpers which includes the ASP.NET Web Pages helper methods. Then I simply added Twitter.Profile, Twitter.Search, Facebook.LikeButton and LinkShare.GetHtml helper methods. It looks very simple. Now just run this application. You will find the following screen,

 

 

          

 

 

 Summary:

          In this article I showed you how you can leverage the ASP.NET Web Pages helper methods in your ASP.NET MVC application. This will make it easy for you to add social engineering, Bing search, share links etc, into your site quickly. Hopefully you will enjoy this article too. You can also download the sample application which also include the assembly of these helper methods.

ASP.NET MVC ASP.NET

Published at DZone with permission of Imran Baloch, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Enabling DB Migrations Using Kubernetes Init
  • The Importance of Delegation in Management Teams
  • How and Why You Should Start Automating DevOps
  • Why Open Source Is Much More Than Just a Free Tier

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: