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

162
Views
¿Cómo acceder al valor?

No puedo acceder al value de la variable cuando lo uso en la instrucción if (@Produkt.KategoriID == value) . Dice "el nombre 'valor' no existe en el contexto actual". ¿Cómo puedo hacer que pueda usar la variable en la declaración if?

 @if (Model != null) { <div style="margin-left: 30%; margin-right: 25%;"> <label> Choose: </label> <select name="Choose" id="select"> <option value="1">None</option> <option value="2">Bronze</option> <option value="3" selected>Silver</option> <option value="4">Gold</option> </select> </div> <script type="text/javascript"> var choice = document.getelementbyid('select'); var value = choice.options[choice.selectedindex].value; </script> if (@Produkt.KategoriID == value) { } }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Básicamente, está tratando de alcanzar la variable js desde el script razor. No se puede alcanzar porque sus ciclos de vida son diferentes. Al final del día, todos los scripts de C# convirtieron códigos HTML, CSS y js y no hay más scripts de C#.

Además, para una situación similar, puede consultar aquí:

¿Cómo pasar un valor a la variable razor desde la variable javascript?

about 4 years ago · Juan Pablo Isaza Report

0

Puedes intentar usar js para agregar html:

 @if (Model != null) { <div style="margin-left: 30%; margin-right: 25%;"> <label> Choose: </label> <select name="Choose" id="select"> <option value="1">None</option> <option value="2">Bronze</option> <option value="3" selected>Silver</option> <option value="4">Gold</option> </select> </div> <script type="text/javascript"> var choice = document.getelementbyid('select'); var value = choice.options[choice.selectedindex].value; </script> <div> </div> <div id="content"></div> }

js:

 $(function () { var choice = document.getElementById('select'); var value = choice.options[choice.selectedindex].value; $("#content").innerHTML = "your html here"; if (1 == value) { var content = ""; content += "your html here"; document.getElementById("content").innerHTML =content; } })
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!