我试图通过if-else条件在mvc控制器中显示警告框。但警报框不显示。我的错误在哪里?如何在mvc 4控制器中显示警报消息?
控制器
public ActionResult Index()
{
int userId = Convert.ToInt32(Session["userId"].ToString());
if (WebMatrix.WebData.WebSecurity.IsAuthenticated)
{
if (userId == 90043)
{
return View();
}
else
{
TempData["Message"] = "You are not authorized.";
return RedirectToAction("Index", "Home");
}
}
else
{
return RedirectToAction("Index", "Home");
}
}
你是什么意思的“警报消息”?请注意,控制器内部的代码在服务器上执行,无需(直接)用户监督。它不代表用户看到并与之交互的最终结果(网页)。此外,由于这不是WinForms项目,所以不能显示消息框。这个不成立。如果你确实想显示一个JavaScript'alert',那么就从'Index'view中进行。 –
嗨安德烈我想在RedirectToAction之前显示警报,如果userId不等于90043 – user3107343
@ user3107343你不能 – Grundy