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

125
Vistas
How to dynamically create a C# Select TagHelper with JavaScript

I have a button then when clicked creates a table row with a select element inside of it. I want to insert a tag helper dynamically using javascript. Is there a way to insert a TagHelper via javascript or am I just going to have to do it the long way and build out the select?

 function createNewRow() {
     var row = `<tr>
     <td><select></select></td>
     <td class="rowControl"><input id="setLeadCheckbox" type="checkbox" /></td>
     <td class="trash-cell"><i class="fa-regular fa-trash-can fa-2x"></i></td>
     </tr>`;

     $('#staffTable').append(row);
 }

I instead want to use the built in .NET Core Select Tag Helper

<select asp-for="SelectedEmployeeId" asp-items="Model.Employees"></select>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can't do it that way. TagHelpers are interpreted. In other words, Razor must see them as actual tags in order to replace them. Here, it's just a JS string, and Razor will not mess with that.The tag helper simply doesn't provide output within a <script> tag, <script> leaves the tag helper unchanged.

You can refer to this link to Dynamically create a drop-down list with JavaScript/jQuery.

about 4 years ago · Juan Pablo Isaza Denunciar

0

TagHelpers are "executed" server-side and they generate html that is then sent to the browser. Javascript runs on the browser/client-side, so you cannot create a TagHelper or any razor syntax from javascript.

about 4 years 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 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