Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

asp.net core 3.1 convert system.string[] 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: #core #convert #javascript #array
ADD COMMENT
Topic
Name
6+8 =