MetaTrader for printing metadata with ASP.NET MVC

I am trying to make a meta tag in my view based on data in my model ... my code looks like this:

<meta name="description" content="<%=Html.Encode(Model.MetaDescription) %>" />  

      

But my output looks like this:

meta name="description" content="&lt;%=Html.Encode(Model.MetaDescription) %>" />  

      

How am I wrong?

+1


a source to share


2 answers


You are probably adding this tag meta

to the tag <head>

that is marked as runat="server"

. Try:

<meta name="description" content='<%=Html.Encode(Model.MetaDescription) %>' />

      



I don't have a clear idea of ​​what the real problem is, as I don't have a complete source, but for a workaround:

<meta name="description" content=<%= "\"" + Html.Encode(Model.MetaDescription) + "\"" %> />

      

+3


a source


Mehrdad's second solution works great and displays valid XHTML, but causes the VS IDE to complain about invalid syntax (it doesn't "see" double quotes during development and thinks they're missing).

The best (working) syntax would be:



<meta name="description" content=<%= "" + Html.Encode(Model.MetaDescription) %> /> 

      

Looks like a bug in the MVC rendering engine, and a blank line at the beginning is a workaround ...

0


a source







All Articles