Search code examples
javascriptc#asp.net.netmeta-tags

How do I add a string from c# function into a meta tag (inside quotes)?


This works

<title><%=MyLib.data.GetMetaTitle()%></title>

This does not

<meta name="description" content="<%=MyLib.data.GetMetaDescription()%>" >

Returns:

<meta name="description" content="&lt;%=MyLib.data.GetMetaDescription()%&gt;" >

This sort of works

<meta name="description" content="\"<%=MyLib.data.GetMetaDescription()%>"\" >

Returns:

<meta name="description" content="\"Meta Description"\" >

SO - I can get the c# function to run outside of quotes, but I can't get the data to appear within quotes in the header.


Solution

  • I understand your concern why this happening because it need the formatted string type value, Here is the solution.

    <meta name="description" content="<%=string.Format("{0}",MyLib.data.GetMetaTitle())%>"/>
    

    Hope it will help you out! In case of any issue kindly let me know.

    Happy Coding