简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM