标签:
方法一:通过Request.Form
        [HttpPost]
        public ActionResult Test()
        {
            string id=Request.Form["id"];
            return View();
        }
方法二:通过映射到FormCollection
        [HttpPost]
        public ActionResult Test(FormCollection form)
        {
            string id = form["id"];
            return View();
        }
方法三:通过映射到控制器方法参数
        [HttpPost]
        public ActionResult Test(string id)
        {
            //id是获取来自View表单POST过来的控件名为id的值
            return View();
        }
方法四:通过映射到视图数据对象
        [HttpPost]
        public ActionResult Test(TModel model)
        {
            string id = model.id;
            return View();
        }
方法五:通过调用UpdateModel方法
        [HttpPost]
        public ActionResult Test()
        {
            TModel model;
            UpdateModel<TModel>(model);
            return View();
        }
以上五种方法都可以获取视图中的值,其中方法一与方法二本质上是相同的,方法四与方法五本质上也是相同的,具体使用哪种方法依据实际情况来选择使用,建议若是获取指定的某一个或某几个的值,可使用方法一或方法三,若是获取整个表单所有的值,则可使用方法四方法五。
原文链接 http://www.tzwhx.com/NewShow/newBodyShow/AJAX_45908.html
ASP.NET MVC 在控制器中接收视图表单POST过来的数据方法
标签:
原文地址:http://www.cnblogs.com/JD-XIAOMEI/p/4386862.html