Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda