MVC 通过Jquery获取视图中所有控件的值

在使用MVC开发Web时,有需求要将页面所有控件及其值传递到客户端与预定义的界面字段配置进行匹配。

之前用的方法是,通过Form提交表单,在控制器中通过Request.Form["字段名称"]获取值的方式。

现在又找到一种方法即通过Jquery 先获取视图中的控件,然后传递即可。

如下获取页面所有input控件

function printTextValue(){
        var texts = $("input:text"),textArray = [];

        texts.each(function(){
                var $this =$(this);

                textArray.push($this.attr("id")+'='+$this.val());

        });
        document.write(textArray.join("<br/>"));

}

  

原文地址:https://www.cnblogs.com/aehyok/p/2858937.html