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

189
Views
asp.net core MVC `@{}` Is it possible to use the variable inside the tag outside the tag
<script>

const labels = [
'Male',
'Female',
];
var count = 0;
@{
    var count=0;
    foreach (var Data in Model)
    {
        if (@Data.PersonGender=="Male")
        {
            count += 1;
        };
        
    }
    
}

  const data = {
    labels: labels,
    datasets: [{
      data: [count, 8],
    }]
  };


  const config = {
      type: 'pie',
      data: data,
      options: {
        responsive: true,
        plugins: {
          legend: {
            position: 'top',
          },
        }
      },
   };

I am trying to use same variable but I can't. My main goal is to show the ratio of the genders of the objects in the list that I created from the SQL table as a pie chart. I think count is calculated correctly but I can't use the variable inside @{} outside.

about 4 years ago · Juan Pablo Isaza
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!