How To Use C# List In Javascript

Today, I want to talk about using C# List in javascript. If you have an Asp.Net MVC Web App, you need to send a list of data from controller to your html page. Now I will explain how to use C# list in javascript.

First we must prepare our list data in controller. As a result, I prepared this controller code for my Razor view. I will send “myList” data to the Razor view.

We must serialize the list to javascript can understand and use it in our html page. This is our javascript code :

Let me explain this code. We must convert this code with “Html.Raw” to escape from quotation marks etc. Without that, list data treats like string. And we have to parse it with “json.parse” to make this list data usable for javascript. You should have a look at my another post about Session Authorization In Asp.Net

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *