MVC 中 注册不成功 或其他操作不成功 提示办法

在Controller中 .cs

                  public  ActionResult AddUser(User u)

                    {

                                     ……

                             try

                              {

                                      ……

                                       GetInsertUser(u);        //  注册  或其他操作方法

                                       retutrn RedirectToAction("SHow","AllUser");

                                }

                               catch

                                {

                                         ViewBag.IsError=true ;

                                         ViewBag.Meaage="对不起,注册失败!";  // 或其他操作失败信息

                                 }

                     }

      然后  在当前的视图(AddUser.cshtml) 页面的最低下加如下代码

          @{

                     if(ViewBag.IsError!=null && ViewBag.IsError )

                         {

                               <script> alert("@ViewBag.Message")  </script>   // 注意alert里面的“”很重要!

                         }

             }

posted @ 2013-11-13 21:14  酒沉吟  阅读(303)  评论(0编辑  收藏  举报