开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜