Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

354
Visualizações
.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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda