This
article will show you how you can integrate twitter, pinterest, facebook,
googleplus and tumblr social sharing buttons using jquery in asp.net mvc.
Some of my
previous articles are as follows: Fixed
Header Web Page Using CSS3 Without jQuery In Asp.Net MVC, CountDown
To Show Under Construction Page Using jQuery In Asp.Net MVC, Bootstrap
Style Dynamic jQuery Dropdowns Menu Using Asp.Net MVC In C#.Net, Stylish
Button Using Css3 In Asp.net,
How
to Get Mouse Pointer Cordinate Inside a Div Using jQuery In Asp.Net, Get
User Detail Like City,County,Region,Zip Code Using IP Address In Asp.Net.
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.
0 comments:
Please let me know your view