Using @someproperty
will assume you're rendering out HTML and make sure it gets encoded to prevent things like cross site scripting. In this instance you want it to render the raw value, in which case you need to use Html.Raw(...)
to render your content in it's raw form.
@section meta {
<meta name="title" content="@Html.Raw(Model.title)" />
}
However, just be aware that if the Model.title
can come from user generated content (or some other untrusted source), you could be opening yourself up to security issues (for example if your Model.title
's value was "test" /> <script ...etc...
", a malicious user could use it to inject code into your pages.
Edit: Just including the content of my comment below for future googlers, since it appears that was the actual solution...
If you put the @Html.Raw(Model.title)
directly in the page somewhere (i.e. not in the meta tag) and it works correctly there, you may be facing the same problem discussed here, in which case you could work around it by using the slightly uglier:
@section meta {
<meta name="title" @Html.Raw("content=\" + Model.title + "\"") />
}