zoukankan      html  css  js  c++  java
  • ASP.NET MVC 在控制器中接收视图表单POST过来的数据方法

    方法一:通过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();
            }

    以上五种方法都可以获取视图中的值,其中方法一与方法二本质上是相同的,方法四与方法五本质上也是相同的,具体使用哪种方法依据实际情况来选择使用,建议若是获取指定的某一个或某几个的值,可使用方法一或方法三,若是获取整个表单所有的值,则可使用方法四方法五。

  • 相关阅读:
    4.FFMPEGAVFrame
    从0到1实现Web端H.265播放器:视频解码篇
    6.AVCodecContext和AVCodec
    7.SwrContext音频重采样使用
    5.AVStream和AVCodecParameters
    3.AVPacket使用
    FFmpeg:AVFrame结构体分析
    9.下载ffmpeg、使QT支持同时编译32位和64位
    1.ffmpeg基础经常使用知识
    2.AVFormatContext和AVInputFormat
  • 原文地址:https://www.cnblogs.com/lanke0/p/5143381.html
Copyright © 2011-2022 走看看