I am trying to show an alert message on submitting a request. The alert message should be the content of ViewBag. Here is my view.
@{
ViewBag.Title = "Request";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@if (!string.IsNullOrEmpty(ViewBag.message))
{
<script type="text/javascript">
var msg = "@ViewBag.message";
alert(msg);
</script>
}
There is no alert even when ViewBag.message has value in it.
Change it to:
<script type="text/javascript">
$(document).ready(function () {
var msg = "@ViewBag.message";
alert(msg);
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.