kez kez - 1 month ago 8
C# Question

define a long array in jquery click function

I have following long type session on server side code

long[] grouparray = ..;

Session["grouplist"] = grouparray;

Now I'm trying to get this session on View Page's jquery click function

$("#gpline").click(function () {

var grouplistvalues = Session["grouplist"];



But this is having error once I debug using firebug

SyntaxError: expected expression, got ']'



You need to use Json.Encode and @Html.Raw on your c# data to make it compatible with your scripts.

Try this.

$("#gpline").click(function () {

    var grouplistvalues = @Html.Raw(Json.Encode(Session["grouplist"])); // converting the session data into array of numbers in javascript variable

    alert(JSON.stringify(grouplistvalues)); // stringify is used only to test.