开发者

Registered Mark does not appear when using @Page.Title!

开发者 https://www.devze.com 2023-02-20 01:10 出处:网络
I am using WebMatrix (I\'m like, addicted to it), for a new site (w开发者_如何学Goell, it\'s just a new version of an existing site) and I have this:

I am using WebMatrix (I'm like, addicted to it), for a new site (w开发者_如何学Goell, it's just a new version of an existing site) and I have this:

_SiteLayout.cshtml:

@{
   <!DOCTYPE html>
   <html>
    <head>
     <meta charset="utf-8" />
     <title>@Page.Title</title>
    </head>
    <body>@RenderBody()</body>
   </html>
}

and...

Default.cshtml:

@{
   Layout = "~/_SiteLayout.cshtml";
   Page.Title = "SexyDomainManager&reg;";
}
<p>Etc</p>

Which should make the title of the page look like this:

SexyDomainManager®

However, it doesn't. Instead, you can actually see &reg; in the title. This only happens when I use @Page.Title. Why? And how do I fix this?


Razor will automatically encode the HTML for you (which is why you don't see the symbol).

You could either put the symbol directly into your string or use the Html.Raw method to return the raw string:

<title>@Html.Raw(Page.Title)</title>


I don't know "WebMatrix", but it obviously HTML encodes the values before including them in the output, so that the developer (you) doesn't need to, which is correct behavior for a web framework.

So if you what the title to contain "®" then write "®":

Page.Title = "SexyDomainManager®";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号