在Controller中實現在頁面彈出提示框,具體代碼如下:

1 public ActionResult LoginCheck() 2 { 3 4 string userName = Request.Form["userName"]; 5 string password = Request.Form["password"]; 6 if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrEmpty(password)) 7 { 8 var script = String.Format("<script>alert('用戶名或者密碼不能為空!');location.href='{0}'</script>", Url.Action("index","Common"));//Url.Action()用於指定跳轉的路徑 9 return Content(script, "text/html"); 10 } 11 12 return RedirectToAction("Index", "Home");//成功時的跳轉路徑 13 14 }
說明:可以根據需要指定跳轉路徑。
參考:
2.mvc彈出提示框