MVC4 js里给对象赋值

摘要:
[HttpPost]publicJsonResultSaveSelectedAcPoint(AcupercePointCriteriaInfooJsonInfo){boolisSeccess=true;//boolmessage=isSeccess;Data=new{isSeccess}};设置

如果需要用js给control传一个对象,那么对象的属性在c#的model必须加public,不然在js赋值时赋不了的,但是不报错,等你调试到control时,这些属性无聊如何都是null,这样会很郁闷的。

controller方法:

 [HttpPost]
        public JsonResult SaveSelectedAcPoint(AcupuncturePointCriteriaInfo oJsonInfo)
        {
            bool isSeccess = true;// this._iConsultation.SaveMyCustomizeCompound(oJsonInfo);
            // bool message =  isSeccess;//== true ? "添加成功" : "添加失败";
            return new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new
                {
                    isSeccess
                }
            };
        }

 model:

 public class AcupuncturePointCriteriaEntity {
        //public int ClientRegisterID { get; set; }
        //public int CaseHistoryID { get; set; }
        public int AcupuncturePointID { get; set; }
        public int Supplement { get; set; }
        public string AdditionalTreatment { get; set; }
        public int AcupReinReducing { get; set; }
        public int NeedleTime { get; set; }
    }
   
    public class AcupuncturePointCriteriaInfo : CommonInfo
    {
        public int ClientRegisterID { get; set; }
        public int CaseHistoryID { get; set; }
        List<AcupuncturePointCriteriaEntity> AcupuncturePointList { get; set; }

    }

  List<AcupuncturePointCriteriaEntity> AcupuncturePointList { get; set; }没有加public

所以在js赋值:

function GetAcupuncturePointList() {
    var caseHistoryID = window.opener.document.getElementById("hidCaseHistoryID").value;
    if (caseHistoryID == null || caseHistoryID == "") {
        caseHistoryID = 0;
    }
  
    var clientRegisterId = window.opener.document.getElementById("hidRegisterId").value;
    var needleTime = $("#txtNeedleTime").val();//留针时间
    var acupuncturePointList = [];
    $("#tbSelAcPoint tr:gt(1)").each(function () {
        acupuncturePointList.push({
            //"ClientRegisterID": clientRegisterId,
            //"CaseHistoryID": caseHistoryID,
            "AcupuncturePointID": $(this).find("td:eq(0)").attr("id"),
            "Supplement": $(this).find("td:eq(1) input[name='rdoAcPoint']:checked").val(),
            "AdditionalTreatment": $(this).find("td:eq(2) input[type='checkbox']:checked").map(function () {
                return $(this).val();
            }).get().join(","),
            "AcupReinReducing": $(this).find("td:eq(3) input[name='rdoAcupReinReducing']:checked").val(),
            "NeedleTime": needleTime
        });
    });
    AcupuncturePointCriteriaInfo.CaseHistoryID = caseHistoryID;
    AcupuncturePointCriteriaInfo.ClientRegisterID = clientRegisterId;
    AcupuncturePointCriteriaInfo.AcupuncturePointList = acupuncturePointList;
    return AcupuncturePointCriteriaInfo;
}

 AcupuncturePointCriteriaInfo.AcupuncturePointList = acupuncturePointList;

永远赋值不了,调试到controller后,发现对象的其他属性都有值,但是这个集合永远为null,困扰了我两个夜晚才找到这个原因,后来加了 public终于不是null了,我想很多童鞋都不会注意这个问题

免责声明:文章转载自《MVC4 js里给对象赋值》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇公司-浪潮:浪潮/inspur各种推导式下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Python接口自动化(九) cookie登录,session保持,参数关联接口

cookie登录博客园,session保持,发布新博客,报错:{'errors': ['用户账号不匹配,请备份未提交的内容并检查当前登录账号'], 'type': 0} import requestsimport jsonimport datetimeheaders={"User-Agent":"Mozilla/5.0 (Windows NT 10.0;...

iOS开发 Masonry的简单使用

首先,在正式使用Masonry之前,我们先来看看在xib中我们是如何使用AutoLayout     从图中我们可以看出,只要设置相应得局限,控制好父视图与子视图之间的关系就应该很ok的拖出你需要的需求。这里就不详细讲解具体拖拽的方法..... 然后,我们按着上图的属性来看看如何简单得使用Masonry 这里是Masonry给我们的属性  @pr...

【转】常用的python模块及安装方法

  adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheetahcherrypy:一个WEB frameworkctypes:用来调用动态链接库DBUtils:数据库连接池django:一个WEB frameworkdocutils:用来写文档的dpkt:数据包的解包和组包...

百度地图在项目中的使用(JS)

废话先: 这个项目是使用ASP.NET MVC 写的,而关于百度地图在项目中的应用不限于ASP.NET MVC 因为我大部分的API的使用是通过Javascript,想在项目中使用百度地图,你得先成为百度的开发者,具体的步骤,在本篇博文中不多叙述。 主题: 在使用百度地图的时候,你得先要获得一个ak 这里就是点击创建应用,它提供了几个类别1.for...

MySQL设置主键字段自增从0001开始

DROP TABLE IF EXISTS `fi_kj_log_test`; CREATE TABLE `fi_kj_log_test` ( `id` bigint(4) unsigned zerofill NOT NULL AUTO_INCREMENT, `ts` bigint(20) DEFAULT NULL, `success` tiny...

26.怎样在Swift中定义宏?

  Swift 中没有宏定义,苹果建议使用let 或者 get 属性来替代宏定义值。虽然没有#define,但我们仍然可以使用 #if 并配合编译的配置来完成条件编译。下面会列出Swift项目开发中的一些常用宏定义,并提供源码。 1.常用字体宏定义 import Foundation import UIKit /// 系统普通字体 var gof_Sy...