Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Passing List String from C# to JavaScript

I am currently trying to check if a value of a string variable is "Apple". Now I need to pass a list of fruits to javascript from C#.

C# Code

List<String> fruits = new List<String>{"Apple","Mango","Orange"}

JavaScript Code

$(document).on('click','#dvAppContent input:checkbox[id*=chkfunction]', function () {
   ToggleApplication(this);
});

function ToggleApplication(currentFunction) {
   var fruitName = $(currentFunction).closest('ui').parent('label').text().trim();    
   If(fruitName == "Apple")
   {
     return true;
   }       
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use Ajax call in JavaScript. Something like this:

<script>  
    $(document).ready(function () {  
        $.ajax({  
            type: "GET",  
            url: "/api/StudentAPI/GetAllStudents",  
            contentType: "application/json; charset=utf-8",  
            dataType: "json",  
            success: function (data) {  
                //alert(JSON.stringify(data));                  
                $("#DIV").html('');   
                var DIV = '';  
                $.each(data, function (i, item) {  
                    var rows = "<tr>" +  
                        "<td id='RegdNo'>" + item.regNo + "</td>" +  
                        "<td id='Name'>" + item.name + "</td>" +  
                        "<td id='Address'>" + item.address + "</td>" +  
                        "<td id='PhoneNo'>" + item.phoneNo + "</td>" +  
                        "<td id='AdmissionDate'>" + Date(item.admissionDate,  
                         "dd-MM-yyyy") + "</td>" +  
                        "</tr>";  
                    $('#Table').append(rows);  
                }); //End of foreach Loop   
                console.log(data);  
            }, //End of AJAX Success function  
  
            failure: function (data) {  
                alert(data.responseText);  
            }, //End of AJAX failure function  
            error: function (data) {  
                alert(data.responseText);  
            } //End of AJAX error function  
  
        });         
    });  
</script>  

And in the backend in c#, something like this:

public class StudentAPIController : Controller  
   {  
       // GET: api/GetAllStudents  
       [HttpGet]  
       public IEnumerable<PersonalDetail> GetAllStudents()  
       {  
           List<PersonalDetail> students = new List<PersonalDetail>  
           {  
           new PersonalDetail{  
                              RegNo = "2017-0001",  
                              Name = "Nishan",  
                              Address = "Kathmandu",  
                              PhoneNo = "9849845061",  
                              AdmissionDate = DateTime.Now  
                              },  
           new PersonalDetail{  
                              RegNo = "2017-0002",  
                              Name = "Namrata Rai",  
                              Address = "Bhaktapur",  
                              PhoneNo = "9849845062",  
                              AdmissionDate = DateTime.Now  
                             },                
           };  
           return students;  
       }  
   }  
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!