Reputation: 2352
I have an asp.net mvc view, in witch i'm setting the value of a textbox using jQuery, as shown in the code bellow.
$("#idTxWhat").val('@ViewBag.myValue');
The problem is, if the value of ViewBag.myValue
contains a special character like (é or è), the text is not shown correctly.
exemple : téléphone => té ;lé ;phone
I tried the solution proposed in this question, but didn't work.
EDIT :
If I do the following :
<div id="myTestValue"></div>
...
$("#myTestValue").append('<span> my value : @ViewBag.myValue</span>');
The value appear correctly : téléphone
Thanks in avance.
Upvotes: 0
Views: 1940
Reputation: 9145
Try this:
$("#idTxWhat").val($("<div>").html("@ViewBag.myValue").text());
Upvotes: 1
Reputation: 94642
Have you tried
$("#idTxWhat").val(unescape('@ViewBag.myValue'));
SECOND TRY:
How about this then
var t = '@ViewBag.myValue';
t = decodeURIComponent(escape(t));
$("#idTxWhat").val(t);
Upvotes: 1