************ in base class which will inherit in all models and @model in _layout.cshtml*******
public class MetaTags
{
public string MetaTitle { get; set; }
public string MetaDescription { get; set; }
public string MetaKeywords { get; set; }
public string ImageName { get; set; }
public string app_id { get; set; }
public string SiteName { get; set; }
public string Url { get; set; }
public MetaTags()
{
ImageName = "https://www.studyabroad.pk/UserEnd/Design/images/LogoForFB.gif";
app_id = "277117662711415";
SiteName = "Studyabroad.pk";
Url = HttpContext.Current.Request.Url.ToString();
}
}
********************** Second Step *****************************
**************** in _layout.cshtml *********************************
@{
if (Model.CurrentPageMetaTags != null)
{
<title>@Model.CurrentPageMetaTags.MetaTitle</title>
<meta name="description" content="@Model.CurrentPageMetaTags.MetaDescription" />
<meta name="keywords" content="@Model.CurrentPageMetaTags.MetaKeywords" />
<meta property="og:type" content="website">
<meta property="og:site_name" content="Studyabroad.pk" />
<meta property="og:title" content="@Model.CurrentPageMetaTags.MetaTitle" />
<meta property="og:description" content="@Model.CurrentPageMetaTags.MetaDescription" />
<meta property="og:url" content="@Model.CurrentPageMetaTags.Url" />
<meta property="og:image" content="@Model.CurrentPageMetaTags.ImageName" />
<meta property="fb:app_id" content="277117662711415" />
<meta property="og:image:width" content="200" />
<meta property="og:image:height" content="200" />
}
}
************************* 3rd step ***********************************
*********** In ViewModel class of specific Page **************************
private University university;
public University UniversityDetail
{
get
{
if (university != null)
{
return university;
}
else
{
university = new UniversityModel().GetUniversityDetail(name.Replace("-"," "));
if (university != null)
{
Title = university.Name;
MetaKeyword = university.Name;
MetaDescription = university.Name;
CurrentPageMetaTags = new MetaTags();
CurrentPageMetaTags.MetaTitle = Title;
CurrentPageMetaTags.MetaKeywords = MetaKeyword;
CurrentPageMetaTags.MetaDescription = MetaDescription;
}
//university.ViewedCounter = university.ViewedCounter + 1;
if (count == 1)
{
university = new UniversityModel().UpdateViewedCounter(university);
count++;
}
if (string.IsNullOrEmpty(university.AddressMapLatitude))
{
university.AddressMapLatitude = "6.927079";
}
if (string.IsNullOrEmpty(university.AddressMapLongitude))
{
university.AddressMapLongitude = "79.861244";
}
if (university.AddressMapZoomlevel == null || university.AddressMapZoomlevel == 0)
{
university.AddressMapZoomlevel = 8;
}
if (university.tblCountry == null || university.tblCountry.Name == null)
{
university.tblCountry = new tblCountry();
university.tblCountry.Name = "Country not spacified";
}
return university;
}
}
}
***************************** That's it **********************************easy
No comments:
Post a Comment