MVC POST 的方法总结

//默认为Get方法请求
        public ActionResult PostDemo()
        {
            return View();
        }
        //标记为Post方式请求,改方法就只能接受post方法请求
        [HttpPost]
        public ActionResult PostDemo(FormCollection form)
        {
            //第一种获取提交表单的方式
            string  name = Request.Form["name"];
            ViewBag.name = name;
            //第二种获取提交表单的方式
            string  name2 = form["name"];
            ViewBag.name2 = name2;
            return View();
        }

猜你喜欢

转载自blog.csdn.net/a22698488/article/details/74923307