Good day! Corrected version (the problem was not in the ViewBag)

I am writing an application on asp.net mvc, and I have a simple action like this:

public ActionResult MyAction(string cyrillicParam) { // здесь параметр превращается вот в это: "           " // какой-то код return View(); } 

In all browsers, everything works as expected. Except Internet Explorer. There I am in cyrillicParam get this: " "

Please tell me how to fix this error?

  • <meta charset = "utf-8" /> - free_ze
  • @free_ze tried, doesn't help - Pupkin
  • With these symptoms, look for a problem on the side of the source HTML and browser. File encoding, page encoding, form parameters, transfer method, layout (check DOCTYPE), etc. As a rule, in the browser developer console you can find out a lot of interesting things on the request itself, even in IE. Oh yes, also indicate the version of IE for which the symptoms persist. - Alex Krass

1 answer 1

ViewBag is not to blame. Enter <h1>Мой текст</h1> to verify.

Most likely the problem is in the encoding of the files or in the selected encoding in the browser.

  • Add <meta charset="utf-8" /> to the head of your page.
  • Ensure that * .cshtml files are saved with UTF-8 encoding (VS usually saves them to UTF-8 with BOM)
  • Make sure that UTF-8 page encoding is selected in the browser or automatically, and not Windows-1251

You can see the encoding, for example, in Notepad ++ (at the bottom of the window to the right). To view the selected encoding in the browser, right-click anywhere on the page and select "Encoding".

Added after updating question

In this case, on the client side, you will need to execute encodeURI("Привет!"); . This function will return the scary string %D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82! , but it will be processed correctly.

  • you're right. The problem is not in VuiewBag. The problem is in the url parameter. I updated the question, please see - Pupkin