我正在尝试显示有关提交请求的提醒消息。警报消息应该是ViewBag的内容。这是我的看法。
@{
ViewBag.Title = "Request";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@if (!string.IsNullOrEmpty(ViewBag.message))
{
<script type="text/javascript">
var msg = "@ViewBag.message";
alert(msg);
</script>
}
即使ViewBag.message中有值,也没有警告。
答案 0 :(得分:0)
将其更改为:
<script type="text/javascript">
$(document).ready(function () {
var msg = "@ViewBag.message";
alert(msg);
});
</script>