SidAhmed
SidAhmed

Reputation: 2352

Special (French) characters in an ASP.NET MVC View

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&#233 ;l&#233 ;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

Answers (3)

Rodolpho Lopes
Rodolpho Lopes

Reputation: 41

You can use @Html.Raw(yourString)

Upvotes: 3

ataravati
ataravati

Reputation: 9145

Try this:

$("#idTxWhat").val($("<div>").html("@ViewBag.myValue").text());

Upvotes: 1

RiggsFolly
RiggsFolly

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

Related Questions