mardi 25 août 2015

ASP.NET MVC Help trying to convert a list to Javascript Array

I'm using ASP.NET MVC (with Razor) and JQuery

I have a list of strings in my controller and I render the partial view passing in the model with the below list.

List<string> list = new List<string>();

On client side I have:

<div id = "test", test-att = @Html.Raw(Json.Encode(Model.list)) />

In my javascript file I do:

var javascriptArray = $('#test').attr('test-att');

I'm expecting a result ["test1", "test2"] but I'm seeing "["test1", "test2"]"

Any ideas on how to fix this?

Aucun commentaire:

Enregistrer un commentaire