0

I am trying to pass a French word from Controller to View using viewbag (The word that I try to pass is : Espèce), but inside the view when I try to affect the viewbag value's to an HTML input type text all I see is : Espéce .

In Controller

ViewBag.T = "Espèce";

In View : I used Jquery to affect the value

$("#T").val("@ViewBag.T").focus();

The HTML Input

<div>

    <input type="type" id="T" value="" />

</div>

The result

enter image description here

irowe
  • 638
  • 11
  • 21
ADS MB
  • 175
  • 11
  • Does this answer your question? [One aspx page to have utf-8 encoding](https://stackoverflow.com/questions/33283697/one-aspx-page-to-have-utf-8-encoding) – irowe Jul 30 '20 at 14:34

2 Answers2

0

Looks like an encoding issue. I'd recommend UTF-8 to ensure you get the accent marks to show up correctly.

From the Microsoft ASP.NET documentation:

To set the encoding for all pages, add a Globalization property to the Web.config file, and then set its fileEncoding, requestEncoding, and responseEncoding attributes, as shown in the following example:

<configuration>   
 <system.web>
   <globalization
      fileEncoding="utf-8"
      requestEncoding="utf-8"
      responseEncoding="utf-8"
      culture="en-US"
      uiCulture="de-DE"
    />   
 </system.web> 
</configuration> 
irowe
  • 638
  • 11
  • 21
0

Try the below jquery code it will work as you expected. But it may introduce an XSS vulnerability. You can refer the link.

$("#T").val($("<div/>").html("@ViewBag.T").text()).focus();