mvc彈出提示框 C#


在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         }
View Code

說明:可以根據需要指定跳轉路徑。

參考:

1.在mvc中彈出提示框

2.mvc彈出提示框

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM