javascript - .net 核心,如何在 ViewComponent 的 javascript 函数中使用 @model
问题描述
我有一个 ViewComponent,我需要在 javascript 函数中使用一些服务器代码,即:获取控制器操作的 url 和一些模型属性
如果我使用它们得到 impostaLingua 未定义错误
我尝试使用全局 js 变量并将其设置在 docReady 但变量未在 docReady 中定义
我无法在 Layout.cshtml 中编写函数,因为我没有服务器变量
正确的方法是什么?
谢谢
@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>
解决方案
推荐阅读
- swift - 如果我子类化一个类,我可以指定一个实例变量应该是某个子类吗?
- jenkins - 错误:无法连接到端口 8080 上的 Cloud Shell(在 google kubernetes 云中部署 Jenkins)
- python - 用于屏蔽每列单个切片的矢量化方法
- voice-recognition - 设备上单字语音识别
- powershell - 在我的脚本中出现错误
- python - 在python中并排添加二维数组
- jenkins - 如何让詹金斯的工作等待其他工作完成?
- r - 如何在 R 中添加总计和 group_by 统计信息
- css - css:四列宽
- css - ionic 4“离子选项”文本换行