R
R
Ruslan2012-09-20 08:05:32
JavaScript
Ruslan, 2012-09-20 08:05:32

Converting strings in c# to be processed correctly in javascript?

How can I convert a string so that it is exactly passed as a parameter to a javascript function? Here is an example, code on ASP.NET MVC3

@{
string xparam="xyz'><\"<!-- 12 -->abc";
}
<img src="x.png" onclick="myfunction('@xparam')" />

Question: what needs to be done with the xparam variable in c# code so that the original string gets into the javascript function.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jonie, 2012-09-20
@jonie

I think he wants to cancel auto-screening. To do this, you need to use Html.Raw().

E
ertaquo, 2012-09-20
@ertaquo

Look here, it might help:
stackoverflow.com/questions/323640/can-i-convert-ac-sharp-string-value-to-an-escaped-string-literal
www.codeproject.com/Articles/371232/Escaping- in-Csharp-characters-strings-string-forma

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question