This is what i've done to get the Alert from the controller
Here is the View Code:
@using (@Html.BeginForm("DoSomething","secure"))
{
<input type="submit" value="get alert" />
}
Here is Controller Code:
[HttpPost]
public ActionResult DoSomething()
{
string message = "hai";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
//return Content("<script type='text/javascript'>alert('Hello there');</script>"); //You can get the alert with this line also
return Content(sb.ToString(), "text/javascript");
}
Even there is no need of script, it directly shows alert when the get alert
button is clicked
Hope it helps