This project is read-only.

Czech special characters and using Html.Raw

Topics: General, Localization
Aug 18, 2011 at 3:22 PM
Edited Aug 18, 2011 at 3:36 PM


I'm new (and beginner in mvc 3) :) And I am learning...
 I've made some web, everything works fine, but I have one little problem. In Czech we have special characters like this: ě š č ř ž ý á í é. I set lang="cs", charset="utf-8"...
Every characters are display properly in frontend, but when I open Source code of page, some characters are display as &#XXX; where XXX is number as you know :) So menu text in source code look as this:

Pro média ("missing" é)
Výroba elektřiny ("missing" ý) and so on...

On other websites written in PHP or where is used Joomla or some other CMS, there are these special characters in source code OK.

So I have an idea :) I want to use @Html.Raw() for content in ~/Core/Shapes/Document.cshtml or in my layout.cshtml BUT... there is the problem. I trying use something like this:

@Display(Html.Raw(Modul.Body)) OR
@Html.Raw(Display(Modul.Body)) OR

var telo = "@Display(Modul.Body)"
@Html.Raw(telo) OR

var telo = new HtmlString(Display(Modul.Body))

And so on....

I am sure that some of these experiments are absolute nonsense...

But How can I achieve that text in frontpage that see user (maybe "Výroba elektřiny") will be displayed in Source code as "Výroba elektřiny" not as "Výroba elektřiny"? 
Or how can I use Html.Raw in this case?


Thanks to everyone :)
And sorry if it is very stupid question :) but I looking for everywhere and nothing found :(

Aug 18, 2011 at 7:36 PM

Actually it's not Orchard specific, and you might have better chances on a Razor or ASP.NET dedicated forum. But be sure if I knew the answer I would have replied ;)

Do you know the origins of the issue ? Is using Html.Raw rendering what you want, but Html.Raw(Display()) not working ?

Aug 19, 2011 at 8:00 AM

No :( When I add <customErrors mode="Off" /> into web.config I get only error 500 internal server error, not what is wrong in code :(

Is using Html.Raw rendering what you want, but Html.Raw(Display()) not working ? /// Yes, this works. But when I add something into brackets, it stop works.
I tried now something like this:

var telo = Modul.Body;
@Html.Raw(Display(telo)) // Error 500

var telo = "Modul.Body";
@Html.Raw(Display(telo)) //  Error 500

only @Html.Raw(Display())  // Ok, without texts and layout :))
as you write yesterday.

Any idea? :)


Aug 22, 2011 at 8:56 PM

And Display(telo) works without the Raw around it?

Aug 24, 2011 at 10:45 AM

Yes @Display(telo) works without Raw...

Aug 24, 2011 at 8:13 PM

Weird. All Raw is doing is returning a new HtmlString, and that is just storing the value without manipulating it in any way. The error is probably in Razor. Can you provide the full stack trace for that 500 error?

Aug 25, 2011 at 9:24 AM

Don't understand... :(

I know that razor can has some errors/mistakes.


But is there some other solution? Maybe exists some code for this, but only I don't know it :) I think that something must exist because what about Russian websites, or Japan/China..? there are a special characters too...


Aug 25, 2011 at 8:26 PM

A good way to test further would be to try the same thing with a string literal:

@("whatever string seems to be the problem")
Aug 25, 2011 at 8:27 PM

Also, having an actual stack trace, as I asked above, would help immensely.

Aug 25, 2011 at 9:48 PM

Oh sorry, I didn't know what means stack trace in cz :D but now I know, tommorow I look into log and write it...

Aug 26, 2011 at 1:33 PM


so I look into logs in App_Data and all logs in time when I tried this with html.raw are empty (I tried it today again and log is empty too)... :( in logs where are some lines there is in "long time ago" when I didn't "playing" with html.raw... And into logs on server I have access denied...

Aug 26, 2011 at 7:12 PM

That's weird in itself, but when you are getting those 500 errors, you should also have the stack traces right on the screen, provided your web.config has custom errors set to on (don't leave it on on your production server by the way).

Aug 31, 2011 at 5:37 PM

you should also have the stack traces right on the screen // yes I know, when I set in web.config custom errors I get this screen not this screen


Aug 31, 2011 at 8:01 PM

OK, can you give me a repro with a simple @("something") that I could try?