connectseekers.com

Wednesday, 6 April 2016

Twitter, Pinterest, Facebook, GooglePlus and Tumblr Social Sharing Buttons Using jQuery In Asp.Net MVC

4/06/2016 - By Pranav Singh 0

This article will show you how you can integrate twitter, pinterest, facebook, googleplus and tumblr social sharing buttons using jquery in asp.net mvc.


So for this article first we will create a new asp.net mvc application and add  a model class file into the model folder.

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

namespace Social_Icon.Models
{
    public class SocialIcomModel
    {
        public string URL { get; set; }
        public string TwitterFaceGoogleText { get; set; }
        public string TwitterFaceGoogleShareSource { get; set; }
        public string PinterestImageURL { get; set; }
        public string PinterestDescription { get; set; }
        public string TumblrName { get; set; }
        public string TumblrDescription { get; set; }
    }
}

Now add a controller class file into the controller folder.

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

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

        public ActionResult Index()
        {
            SocialIcomModel socialIcomModel = new SocialIcomModel();
            socialIcomModel.URL = "http://www.aspdotnet-pools.com";
            socialIcomModel.TwitterFaceGoogleText = "Very cooll Asp.net blog website!";
            socialIcomModel.TwitterFaceGoogleShareSource = "Aspdotnet-pools";
            socialIcomModel.PinterestImageURL = "http://www.connectseekers.com/images/connect-logo.png";
            socialIcomModel.PinterestDescription = "A classified website";
            socialIcomModel.TumblrName = "Very cool Asp.net blog website!";
            socialIcomModel.TumblrDescription = "There is a new article for social plugin!";
            return View(socialIcomModel);
        }

    }
}

Now create the view of and add the below library and css reference into the page header.

  <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <link href="cool-share/plugin.css" media="all" rel="stylesheet" />
    <link href="css/styles.css" rel="stylesheet" />
    <script src="cool-share/plugin.js"></script>

After this check the complete code.

@model Social_Icon.Models.SocialIcomModel
@{
    ViewBag.Title = "Twitter, Pinterest, Facebook, GooglePlus and Tumblr Social Sharing Buttons Using jQuery In Asp.Net MVC";
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <link href="cool-share/plugin.css" media="all" rel="stylesheet" />
    <link href="css/styles.css" rel="stylesheet" />
    <script src="cool-share/plugin.js"></script>
}
<center>
    <h2>Social Share Icon In MVC</h2>
    <br /><br />
</center>
<br /><br />
<span class="socialShare"> </span>
<script>
    $(function () {

        var url = '@Model.URL';
        var options = {

            twitter: {
                text: '@Model.TwitterFaceGoogleText',
                via: '@Model.TwitterFaceGoogleShareSource'
            },
            pinterest: {
                media: '@Model.PinterestImageURL',
                description: '@Model.PinterestDescription'
            },
            tumblr: {
                name: '@Model.TumblrName',
                description: '@Model.TumblrDescription'
            },
            facebook: true,
            googlePlus: true,
            pinterest: true,
            tumblr: true
        };

        $('.socialShare').shareButtons(url, options);
    });
</script>

In above code check the var option. In this I have mark true to  the social icon for displaying. If we make it false on that case icon will now be visible.

Now we have done run the application to check the output.




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
Email Id : contact@aspdotnet-pools.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


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top