MVC4 js里给对象赋值
2014-04-25 22:47
363 查看
如果需要用js给control传一个对象,那么对象的属性在c#的model必须加public,不然在js赋值时赋不了的,但是不报错,等你调试到control时,这些属性无聊如何都是null,这样会很郁闷的。
controller方法:
model:
List<AcupuncturePointCriteriaEntity> AcupuncturePointList { get; set; }没有加public
所以在js赋值:
AcupuncturePointCriteriaInfo.AcupuncturePointList = acupuncturePointList;
永远赋值不了,调试到controller后,发现对象的其他属性都有值,但是这个集合永远为null,困扰了我两个夜晚才找到这个原因,后来加了 public终于不是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了,我想很多童鞋都不会注意这个问题
相关文章推荐
- Html Javascript Checkbox 全选/全不选
- html5游戏引擎-Pharse.js学习笔记(一)
- JSP页面打印
- JavaScript 隐式转换
- JSP Filter执行流程猜想
- javascript实现图片无缝滚动(scrollLeft的用法介绍)
- Phaser游戏框架 鼠标mouse事件以及触摸touch事件
- javascript系列之DOM(一)
- js真正了解面向对象
- 搜狗浏览器特性页面JS
- Javascript刷新页面的几种方法
- Jsp 中的ajax
- C# WebBrowser控件"自由的"执行JavaScript代码
- JavaScript设计模式之一封装
- JavaScript设计模式之一封装
- 【翻译】探究Ext JS 5和Sencha Touch的布局系统
- ssh三大框架集成后,jsp中采用forword标签提交时会报错的解决方案
- ssh三大框架集成后,jsp中采用forword标签提交时会报错的解决方案
- 【翻译】探究Ext JS 5和Sencha Touch的布局系统
- 【翻译】探究Ext JS 5和Sencha Touch的布局系统