从其他页面重定向时不执行警报
Alert not executing when redirected from other page
我在 MVC 视图的正文标记中有以下代码。问题是警告消息在第一次加载页面时显示,但当控件通过重定向时它没有执行。
此外,我已经使用断点来查看代码正在执行但它不执行警报行。
@{
<script type="text/javascript">
@if (TempData["notice"] != null)
{
@:alert(TempData["notice"]);
}
else
{
@:alert("No notice");
}
</script>
}
if you want to use tamp data value in javascript use this syntax
'@TempData["notice"]'
@{
<script type="text/javascript">
@if (TempData["notice"] != null)
{
@:alert('@TempData["notice"]');
}
else
{
@:alert('@TempData["no notice"]');
}
</script>
}
我在 MVC 视图的正文标记中有以下代码。问题是警告消息在第一次加载页面时显示,但当控件通过重定向时它没有执行。
此外,我已经使用断点来查看代码正在执行但它不执行警报行。
@{
<script type="text/javascript">
@if (TempData["notice"] != null)
{
@:alert(TempData["notice"]);
}
else
{
@:alert("No notice");
}
</script>
}
if you want to use tamp data value in javascript use this syntax
'@TempData["notice"]'
@{
<script type="text/javascript">
@if (TempData["notice"] != null)
{
@:alert('@TempData["notice"]');
}
else
{
@:alert('@TempData["no notice"]');
}
</script>
}