Exemplo n.º 1
0
 //public ActionResult TestAction(string Content)
 public ActionResult TestAction(TestFormModel form)
 {
     ViewData["Content"] = form.Content;
     ViewData["UserId"]  = form.UserId;
     ViewData["Age"]     = form.Age;
     return(View());
 }
Exemplo n.º 2
0
        /*public ActionResult TestAction(string Content)
         * {
         *  ViewData["Content"] = Content;
         *
         *  return View();
         * }*/

        /*public ActionResult TestAction(FormCollection form)
         * {
         *  ViewData["Content"] = form["Content"];
         *
         *  return View();
         * }*/

        /*public ActionResult TestAction(TestFormModel form)
         * {
         *  ViewData["Content"] = form.Content;
         *  ViewData["UserId"] = form.UserId;
         *
         *  return View();
         * }*/

        /*public ActionResult TestAction(TestFormModel form)
         * {
         *  if (!ModelState.IsValid)
         *  {
         *      ViewData["Message"] = "未通過驗證!";
         *      return View();
         *  }
         *  else
         *  {
         *      ViewData["Message"] = "已通過驗證!";
         *      ViewData["Content"] = form.Content;
         *      ViewData["UserId"] = form.UserId;
         *
         *      return View();
         *  }
         * }*/

        /* public ActionResult TestAction(TestFormModel form)
         * {
         *   if(!ModelState.IsValid)
         *   {
         *       ViewData["Message"] = "未通過驗證!";
         *       return View();
         *   }
         *   else
         *   {
         *       form.Time = DateTime.Now;
         *       ViewData["Message"] = "已通過驗證!";
         *       ViewData["Content"] = form.Content;
         *       ViewData["UserId"] = form.UserId;
         *       ViewData["Time"] = form.Time;
         *
         *       return View();
         *   }
         * }*/

        /*public ActionResult TestAction(TestFormModel form)
         * {
         *  UpdateModel<TestFormModel>(form);
         *  return Redirect("/");
         * } */

        public ActionResult TestAction(TestFormModel form)
        {
            if (!TryUpdateModel <TestFormModel>(form))
            {
                ViewData["Message"] = "模型連結失敗!";
                return(View());
            }
            return(Redirect("/"));
        }