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

355
Vistas
.net core, How to user @model inside javascript function in ViewComponent

i have a ViewComponent where i need some server code inside javascript function, ie: get url of a controller action and some Model properties

if i use them got impostaLingua is not defined error

i try to use a global js variable and set it on docReady but got variable not defined in docReady

i cannot write function in Layout.cshtml because there i don't have the server variable

what is the correct way to do it?

Thanks

@model UI.WebApp.Models.MyModel

@(Html.DevExtreme().Lookup()
    .DataSource(Model.LingueSupportate)
    .ID("ddlLingua")
    .Value(Model.LinguaCorrente.TwoLetterISOLanguageName)
    .OnSelectionChanged("function(e) {impostaLingua(e);}")

<script>
var a;
docReady(function () {
    a = @Model.LinguaCorrente;
});

function impostaLingua(e) {
    if(e.selectedItem.Value != @Model.LinguaCorrente)
        document.location.href = '@Url.Action("ImpostaLingua", "Master")?culture=' + e.selectedItem.Value '&returnUrl=' + @Model.PercorsoPagina;
}
</script>
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