My folder organization uses _layout.cshtml in its root. That _layout contains the common <head></head> tag were meta tags are supposed to reside. I use the @RenderBody() command inside the <body> tag of the _layout. My pages work as designed, but where
to put meta tags particular to individual pages. Some pages need to be followed by robots and some don't. Each page needs a unique description and keyword set. The _layout page just isn't the right place. So, where do you put meta tags? Is it like @Page.Title
where razor syntax can populate per page?
Thanks
With Regards
Abhishek Rajiv Luv
"Helpful then please Mark as Answer"
http://www.codeabstract.com/
http://pluralsight.com/training/users/abhishekluv
In case that. You create some like two PageLayouts. Like One for those who need to be followed by crawlers(Who should have the robots) and one for those who dont need crawlers.
Than just place the code for that in the server side for each page.
This is pretty handy, easy too.
You dont need to write the code on every page. All you need is to write page names for the page needed there!
And that Page.Title is not the place to set the meta tags. Page.Title is used to set the page title.
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
Great.
You can even render the content of any .cshtml page using this method @RenderPage n pass the name of that page.
Thanks
With Regards
Abhishek Rajiv Luv
"Helpful then please Mark as Answer"
http://www.codeabstract.com/
http://pluralsight.com/training/users/abhishekluv
Dear Its not about being lengthy or simple. Its about what you want to do.
I use it on my clients site. For displaying the product categories on the front end.
The page consists of a select statement querying the categories table with a foreach loop displaying each category within a ul and li tag.
RenderPage method has to be only declared within the _Layout.cshtml. Thats it. And with Layout = '' ''; it can be used on all of your page.
Thanks
With Regards
Abhishek Rajiv Luv
"Helpful then please Mark as Answer"
http://www.codeabstract.com/
http://pluralsight.com/training/users/abhishekluv
DMT20601
Member
86 Points
197 Posts
Meta tags ... Where do you put them.
Dec 21, 2012 12:52 AM|LINK
My folder organization uses _layout.cshtml in its root. That _layout contains the common <head></head> tag were meta tags are supposed to reside. I use the @RenderBody() command inside the <body> tag of the _layout. My pages work as designed, but where to put meta tags particular to individual pages. Some pages need to be followed by robots and some don't. Each page needs a unique description and keyword set. The _layout page just isn't the right place. So, where do you put meta tags? Is it like @Page.Title where razor syntax can populate per page?
Thanks
Dallas
Abhishek Luv
Participant
1736 Points
468 Posts
Re: Meta tags ... Where do you put them.
Dec 21, 2012 01:33 AM|LINK
You can do something like this.
Put this code in the _Layout.cshtml below the title tag.
@RenderSection("head")
Then inside every page of your website you need to define this section of the code. This section of code will be different on every page.
Give it a try. Hope this helps
With Regards
Abhishek Rajiv Luv
"Helpful then please Mark as Answer"
http://www.codeabstract.com/
http://pluralsight.com/training/users/abhishekluv
DMT20601
Member
86 Points
197 Posts
Re: Meta tags ... Where do you put them.
Dec 21, 2012 12:32 PM|LINK
Excellent ... that solved more than one problem ... I extended your suggestion to
@RenderSection("metatags", required: false)
that lets me use the section only when needed per page
and because I have custom external .css files for some pages, (also required for the <head> tag), I created
@RenderSection("pagecss", required: false)
pages that require the external css file will have the section
@section pagecss { <link href="aboutpage.css" rel="stylesheet" type="text/css" /> } (one line of code when needed ... sweet)
and it all happens in the <head> tag that is in the _layout.
Afzaal.Ahmad...
Contributor
2662 Points
1040 Posts
Re: Meta tags ... Where do you put them.
Dec 21, 2012 12:44 PM|LINK
In case that. You create some like two PageLayouts. Like One for those who need to be followed by crawlers(Who should have the robots) and one for those who dont need crawlers.
Than just place the code for that in the server side for each page.
This is pretty handy, easy too.
You dont need to write the code on every page. All you need is to write page names for the page needed there!
And that Page.Title is not the place to set the meta tags. Page.Title is used to set the page title.
~~! FIREWALL !~~
Abhishek Luv
Participant
1736 Points
468 Posts
Re: Meta tags ... Where do you put them.
Dec 21, 2012 12:56 PM|LINK
Great.
You can even render the content of any .cshtml page using this method @RenderPage n pass the name of that page.
With Regards
Abhishek Rajiv Luv
"Helpful then please Mark as Answer"
http://www.codeabstract.com/
http://pluralsight.com/training/users/abhishekluv
Afzaal.Ahmad...
Contributor
2662 Points
1040 Posts
Re: Meta tags ... Where do you put them.
Dec 21, 2012 01:06 PM|LINK
Thats also a lengthy one!
And the asker is a beginner. So we should give answers according to him! Not a C# pro.
~~! FIREWALL !~~
Abhishek Luv
Participant
1736 Points
468 Posts
Re: Meta tags ... Where do you put them.
Dec 22, 2012 09:48 AM|LINK
Dear Its not about being lengthy or simple. Its about what you want to do.
I use it on my clients site. For displaying the product categories on the front end.
The page consists of a select statement querying the categories table with a foreach loop displaying each category within a ul and li tag.
RenderPage method has to be only declared within the _Layout.cshtml. Thats it. And with Layout = '' ''; it can be used on all of your page.
With Regards
Abhishek Rajiv Luv
"Helpful then please Mark as Answer"
http://www.codeabstract.com/
http://pluralsight.com/training/users/abhishekluv