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>