0

I am trying to pass a c# list parameter using an onclick to a jquery method. It refuses to go to the method I am assuming its the brackets [] that causes that and the string inside the list have slashes & other characters. A string inside the list might look like this; "*abc/def-"

Please assist

<input type="radio" class="btn-check" value="Maybe" name="ckhanswerA" id="chk" onclick="nextSlide(@Json.Serialize(@question))" />

function nextSlide(question) {
    debugger;
    var myList = JSON.parse(question);

}
Anele Ngqandu
  • 115
  • 1
  • 17

1 Answers1

0

You need to escape the generated JSON so that it can be used in the string variable.

<input type="radio" class="btn-check" value="Maybe" name="ckhanswerA" id="chk" onclick='nextSlide(@HttpUtility.JavaScriptStringEncode(Json.Serialize(@question)))' />

reference: How to escape JSON string?

Nitin Sawant
  • 7,278
  • 9
  • 52
  • 98