I am looking for a function to add meta title and description when I enter and call values in view at .net core. I have tried the following code but it did not.How do I include HtmlMeta and Page? Does this code work for me? I am waiting for your help.
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = "Your Page Title";
HtmlMeta metaDescription = new HtmlMeta();
metaDescription.Name = "description";
metaDescription.Content = "Your Page Description";
Page.Header.Controls.Add(metaDescription);
HtmlMeta metaKeywords = new HtmlMeta();
metaKeywords.Name = "keywords";
metaKeywords.Content = "Your Page Keywords";
Page.Header.Controls.Add(metaKeywords);
}
In the layout page add new section inside
<head>
tags:Then you can add meta tags to the header section from any view:
In your page model you can provide the values for
Description
andKeyWords
then pass it to the view.