Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

96
Vistas
How access JavaScript variable inside c# code

Here in my ASP .NET Core MVC project I call JavaScript function with a parameter.

 <span onclick="workloadFunction(11)">Click</span>

Then in the function I wants to loop my model data and check a condition with if statement. So if statement write with c# but I cannot access the JavaScript parameter value inside the if statement.

<script>
function workloadFunction(idvalue) {
   @foreach(var project in Model.activeProjects)
   {
      @if(project.id == idvalue)
      {
          //rest of code
      }
   }
</script>

I wants to access 'idvalue' inside the if statement.

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

 <script>
    function workloadFunction(idvalue) {
     var items = @Html.Raw(Json.Encode(Model.activeProjects));
      for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (item.id == idvalue) {
             //rest of code
           }
         }
      }
 </script>
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.