Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor trying to show text with accents

I'm trying to show some text between html tags, I'm using @HTML.Raw method to accomplish this, the code snippet look like this:

<!-- SEO -->
<title>@Html.Raw(Model.Title)</title>
<meta name="Description" content="@Html.Raw(Model.Description)">
<meta name="KEYWORDS" content="@Html.Raw(Model.Keywords)">
<!-- END SEO -->

Description: @Html.Raw(Model.Description)
Keywords: @Html.Raw(Model.Keywords)

But after the code execute, it show like this:

<!-- SEO -->
<title>FÚTBOL - El portal de los hinchas del fútbol</title>
<meta name="Description" content="F&#218;TBOL - El portal de los hinchas del f&#250;tbol">
<meta name="KEYWORDS" content="F&#250;tbol,hinchas">
<!-- END SEO -->
Description: FÚTBOL - El portal de los hinchas del fútbol
Keywords: Fútbol, hinchas

Something happend when the escaped string is between the " character.

Does anyone know why is this happening?

EDIT

The content of the variables is exactly like this:

Title: FÚTBOL - El portal de los hinchas del fútbol
Description: FÚTBOL - El portal de los hinchas del fútbol
Keywords: Fútbol, hinchas

The charset and the doctype in my _Layout is:

<!DOCTYPE html>
<html lang="es" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://ogp.me/ns#">
<head>     
  <meta charset="utf-8" />

The problem is not the case of the letters its ok that its shows Ú or ú. What i dont unserstand is why its escape the letter in one case and not in the other,

like image 892
dnlgmzddr Avatar asked Sep 05 '25 03:09

dnlgmzddr


2 Answers

My suggestion is use @Html.Raw("your string") whenever you want to force the Raw string.

like image 179
David Graça Avatar answered Sep 07 '25 19:09

David Graça


Since &x250; is "ú" and 218 is "Ú" what is the problem? You're just seeing some cases of using an HTML entity and not in other cases.

Providing you're delivering the output with a suitable encoding the end result will be the same – with the entities it'll be the client doing the un-encoding.

like image 41
Richard Avatar answered Sep 07 '25 21:09

Richard