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 .
Some of my previous articles as follows: Bootstrap
3 and jQuery Form Validation Plugin in Asp.Net MVC, MultiSelect
DropdownList Using jQuery in Asp.Net MVC and C#.Net, Three
Level Menus With Disable Menu Item Using jQuery In Asp.Net, jQuery
Dialog Box Open with Blind and Close With Explode Effect in Asp.Net, jQuery
Digital Clock For Asp.Net, MVC and HTML Applications, jQuery
Datepicker Calendar With Slide Down Effect In Asp.Net, jQuery
Code To Select Multiple Item By Pressing Ctrl Button In Asp.Net, jQuery
Animated Resizable Panel OR Div Control On Mouse Click In Asp.Net.
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
0 comments:
Please let me know your view