When I use @Html.Raw(mystring) normal it renders properly example:
@{ ViewBag.Title = "My Site®"; }
<title>@Html.Raw(ViewBag.Title)</title>
Will properly render <title>My Site®</title>
but when I use it in an attribute:
<meta name="description" content="@Html.Raw(ViewBag.Title)" />
It renders <meta name="description" content="My Site&reg;" />
which is not correct because then it will not render the registered mark.
How do you correct this behavior?
Raw(Object)Returns markup that is not HTML encoded.
The Html. Raw Helper Method is used to display HTML in Raw format i.e. without encoding in ASP.Net MVC Razor. In this article I will explain with an example, how to use Html.
With the Mvc templating and IPublishedContent @Model can be the 'model' part from Mvc but you can also hydrate your own strongly typed models with data from the same objects. In fact, I have recently been contributing to a Mvc hybrid framework where you can combine the two approaches.
@page makes the file into an MVC action, which means that it handles requests directly, without going through a controller. @page must be the first Razor directive on a page. @page affects the behavior of other Razor constructs. Razor Pages file names have a .
As patridge pointed out in his answer you can just include the attribute markup in the parameter to .Raw
.
In your case that would result in something similar to the following:
<meta name="description" @Html.Raw("content=\"My Site&reg;\"") />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With