Posted by Balaji Sathe
in Thursday, March 6, 2014
In controller action:
if(success)
{
TempData["Alert"] = "Alert message";
}
The view which SomeAction action returns (or in layout view):
@{
var message = TempData["Alert"] ?? string.Empty;
}
<script type="text/javascript">
var message = '@message';
if(message)
alert(message);
</script>
Go to controller:
[HttpPost]
public ActionResult Index(ModelName objmodel)
{
try
{
TempData["AlertMessage"] = "Success Alert Message";
return RedirectToAction("Index");
}
catch(Exception ex)
{
TempData["AlertMessage"] = "Exception Message.";
return RedirectToAction("Index");
}
}
In _Layout.cshtml:
<head>
@{
var message = TempData["AlertMessage"] ?? string.Empty;
}
<script type="text/javascript">
var message = "@message";
if (message)
alert(message);
</script>
</head>
0 Comments Received
Leave A Reply