Monday, 7 March 2016

Social Share Buttons of Facebook, Twitter, Google Plus and Pinterest Using jQuery in Asp.Net MVC

3/07/2016 - By Pranav Singh 0

This article will show you how you can create a social share buttons of facebook, twitter, google + and Pinterest using jquery in asp.net mvc. In this I have used pretty plugin. This plugin you can use in the your asp.net application, mvc, mvc2,mvc3,mvc4,mvc5,mvc6 .


So for this article first we will create a new asp.net mvc application. Now create a model class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MvcApplication1.Models
{
    public class SocialModel
    {
        public string twitter { get; set; }
        public string facebook { get; set; }
        public string googleplush { get; set; }
        public string pinit { get; set; }
        public string linkedin { get; set; }
    }
}

Now controller class file and add the below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            SocialModel objsocialmodel = new SocialModel();
            objsocialmodel.twitter = "http://yoururl.com";
            objsocialmodel.facebook = "http://yoururl.com";
            objsocialmodel.googleplush = "http://yoururl.com";
            objsocialmodel.pinit = "http://yoururl.com";
            objsocialmodel.linkedin = "http://yoururl.com";
            return View(objsocialmodel);
        }
    }
}

Here in above code I have assign the social like link in each model property. Now create the view and add the below library reference in you view.

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet" type="text/css" />
<script src=".../../Content/jquery.prettySocial.js" type="text/javascript"></script>
<link href="../../Content/messagebody.css" rel="stylesheet" type="text/css" />

 After this add the below code into the view.

@model MvcApplication1.Models.SocialModel    
@{
    ViewBag.Title = "Social Share Buttons of Facebook, Twitter, Google + and Pinterest Using jQuery in Asp.Net MVC";
}
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet" type="text/css" />
<script src=".../../Content/jquery.prettySocial.js" type="text/javascript"></script>
<link href="../../Content/messagebody.css" rel="stylesheet" type="text/css" />

<div class="social-container">
    <div class="links">
        <a href="@Model.twitter" data-type="twitter" class="prettySocial fa fa-twitter"></a>
        <a href="@Model.facebook" data-type="facebook" class="prettySocial fa fa-facebook"></a>
        <a href="@Model.googleplush" data-type="googleplus" class="prettySocial fa fa-google-plus"></a>
        <a href="@Model.pinit" data-type="pinterest" class="prettySocial fa fa-pinterest"></a>
        <a href="@Model.linkedin" data-type="linkedin"  class="prettySocial fa fa-linkedin"></a>
    </div>
</div>

In this I have assign the model url property. Now we have done run the application to check the output.


DOWNLOAD

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top