Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

system collections generic list to javascript array

//Controller content
string[] array = {"Value1", "Value2", "Value3", "Value4"};
ViewData["Array"] = array;
//OR
List<string> array = new List<string>();
array.Add("value1");
ViewData["Array"] = array.ToArray();
//View content
<script>
	$(document).ready(function () {
    	var array = @Html.Raw(Json.Serialize(ViewData["Array"]));
    	console.log("Array", erros.length);
    	$.each(array, function (key, value) {
        	console.log("Content", value);
    	});
	});
</script>
 
PREVIOUS NEXT
Tagged: #system #collections #generic #list #javascript #array
ADD COMMENT
Topic
Name
6+3 =