Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • yauhen 5 posts 64 karma points
    Dec 30, 2014 @ 10:44
    yauhen
    0

    Umlauts rendered incorrectly inside html attributes

    Hello,

    I have problems with encoding umlauts inside umbraco views when rendering them inside html attributes. All is okay when symbols are strings inside view. But when they are output from code (@) they don't render correctly. So outputing some German characters results to html/unicode encoded symbols. Standart Html.Raw, new HtmlString solutions doesn't help. I have tried to specify culture in web.config in umbraco admin to "de" - without any success. I have tried to recreate view inside MS Visual Studio and copied original content to check possible incorrect file encoding - without any success. So here is fragment of view:

    <!DOCTYPE html>
    <html itemscope itemtype="http://schema.org/Organization">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Title</title>
        <meta name="description" content="@Html.Raw("für")" />
        <meta name="description" content="@(new HtmlString("für"))" />
        <meta name="description" content="für" />
    </head>
    

    this results in:

    ...
    <meta name="description" content="f&#252;r" />
    <meta name="description" content="f&#252;r" />
    <meta name="description" content="für" />
    

    The only solution that really works but is very ugly is:

    @{
        ViewContext.Writer.Write("<meta name=\"description\" content=\"für\" />");
    }
    

    I am using Umbraco version 7.2.1 assembly: 1.0.5462.37503

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Dec 30, 2014 @ 11:40
    Alex Skrypnyk
    100

    Hi,

    Try this :

    @Html.Raw(HttpUtility.HtmlDecode(Model.Content));

    But it's not problem of Umbraco ) It's just razor.

    Thanks

  • yauhen 5 posts 64 karma points
    Dec 30, 2014 @ 12:42
    yauhen
    0

    Hello,

    Strange because in Razor Html.Raw is enough. And it doesn't helps also (accidentally marked as solution and could not unmark):

    <meta name="description" content="@Html.Raw(HttpUtility.HtmlDecode("für"))" />
    

    results:

    <meta name="description" content="f&#252;r" />
    
  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Dec 30, 2014 @ 13:44
    Alex Skrypnyk
    0

    From where will you get this data ?

  • yauhen 5 posts 64 karma points
    Dec 30, 2014 @ 14:43
    yauhen
    0

    Hello,

    results are form Chrome-view source. Markup is inside razor masterpage cshtml (but could be inside cshtml of view itself it doesn't metter). Please also note that

    <meta name="description" content="@Html.Raw("für")" />
    

    inside regular MVC project produces correct:

      <meta name="description" content="für" />
    
Please Sign in or register to post replies

Write your reply to:

Draft