I am working on mvc2. I want used Meta tags. I am new on the meta tags and seo. How can used meta tags on my page? What is the best way to used meta tags on mvc?
问题:
回答1:
From a programmer/technology point of view: meta tags are just tags.
What the content of your meta tags should be, and how to generate them, is application specific.
- Google's article on meta tags
- W3schools has a nice simple article
回答2:
Meta tags play an ever decreasing role in SEO these days.
However, in relation to MVC, you can set your masterpage up along the following lines:
<head runat="server">
<title>
<asp:ContentPlaceHolder ID="TitleContent" runat="server" />
</title>
<asp:ContentPlaceHolder
ID="MetaPlaceHolder" runat="server">
<meta name="keywords" content="<%= ViewData["keywords"] %>" />
<meta name="description" content="<%= ViewData["description"] %>" />
</asp:ContentPlaceHolder>
// lots os stuff missed out!!
</head>
<body>// more suff missed etc</body>
and then pass the ViewData from your individual controller actions to populate the 'keywords' and 'description' sections. There are other ways, but this one is fairly simple to get up and running without major disruption to your existing codebase.
usage - add the following to each required controller action
public ActionResult Index()
{
// data would obviously come from some datastore but hardcoded for now below
ViewData["keywords"] = "speed, camera, action";
ViewData["description"] = "crime dun wrong";
// other stuff happening too
}
That said, you should more importantly be looking at:
- keyword density
- outbound/inbound links
- img alt tags
- page titles
- H1/H2 contents
- long URL segmentation and applicability
as these play an ever increasing importance in SEO these days. all of the above should be easily searchable on google.
回答3:
I think Jim is over-complicating it just a bit with the placeholder bit - it's not necessary. Just do this:
In _Layout head section:
<meta name="description" content=@ViewData["Description"]/>
In the controller:
ViewData["Description"] = "My site has all the goodies!!";
Also no need to wrap it in a conditional; it won't throw an error. If you don't set ViewData in the controller the tag will just be empty:
<meta name="description"/>