如何将 javascript 放入 if
block 中?
@if(TempData["notification-message"] != null) {
$('#notification').jnotifyAddMessage({
text: '@TempData["notification-message"]',
permanent: false
});
}
我得到了错误的编译常量值
。
最佳答案
$
标志不会指示 Razor 切换到 Html 模式。
将脚本包裹在<text>
中标签:
@if(!string.IsNullOrEmpty((TempData["notification-message"] as string))) {
<text>
$('#notification').jnotifyAddMessage({
text: '@TempData["notification-message"].ToString(),
permanent: false
});
</text>
}
关于javascript - ASP.NET MVC - Razor 和 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8293801/