我正在发布一个Jquery Json序列化对象到我的控制器,但并非所有的数据都通过了。其中一个成员是Json序列化的复杂类型。这是没有通过控制器。如何通过JQuery发送复杂类型到MVC2控制器(Ajax)
这是我通过Ajax post传递给我的控制器的类。请注意复杂类型RoutingRuleModel。
SourceCodeModel.cs:
[Serializable]
public class SourceCodeModel
{
public string SourceCode { get; set; }
public bool IsActive { get; set; }
public string LastChangedBy { get; set; }
public string LocationCode { get; set; }
public string Vendor { get; set; }
public RoutingRuleModel RuleModel { get; set; }
}
RoutingRuleModel.cs:
[Serializable]
public class RoutingRuleModel
{
public string AdaStuInfoSysId { get; set; }
public string AdaInitials{ get; set; }
public string LocationCode { get; set; }
public string Vendor { get; set; }
public string RuleName { get; set; }
public string RuleStatus { get; set; }
public int RuleId { get; set; }
}
这里是我正在构建的模型在JavaScript:
getSourceCodeModel = function (sourceCode, isActive, lastChangedBy, locationCode, ruleModel) {
// Retrieves a SourceCodeModel object that can be JSON-serialized
return ({
SourceCode: sourceCode,
IsActive: isActive,
LastChangedBy: lastChangedBy,
LocationCode: locationCode,
Vendor: ruleModel.Vendor,
RuleModel: [{ AdaStuInfoSysId: ruleModel.AdaStuInfoSysId, AdaInitials: ruleModel.AdaInitials, LocationCode: ruleModel.locationCode,
Vendor: ruleModel.Vendor, RuleName: ruleModel.RuleName, RuleStatus: ruleModel.RuleStatus, RuleId: ruleModel.RuleId}]
});
};
这里是我的JQuery Ajax调用:
$.ajax({
type: "POST",
url: "/LeadRoutingConsole/VendorLeadRouting/PostSourceCode",
data: sourceCodeModel,
datatype: "json",
success: Commit_success,
error: Commit_error,
complete: function (jqXHR) { }
});
这里是我的控制器的操作方法:
[HttpPost]
public JsonResult PostSourceCode(SourceCodeModel model)
{
// perform the save op
var viewModel = new SourceCodesViewModel();
viewModel.PostSourceCode(model);
return Json(model);
}
问题:SourceCodeModel包含除了它的复杂成员正确的价值观:RuleModel,这回来的RoutingRuleModel用默认值(null或0的)值。
谢谢您的答复,并在没有硬编码的URL的建议。我提出了修复建议,但仍然无效!这是来自FireBird:'SourceCode = 333www&IsActive = 1&LastChangedBy =&LocationCode = AICA&Vendor = STUSCOUT&RuleModel%5BAdaStuInfoSysId%5D =&RuleModel%5BAdaInitials%5D =&RuleModel%5BLocationCode%5D = AICA&RuleModel%5BVendor%5D = STUSCOUT&RuleModel%5BRuleName%5D =&RuleModel%5BRuleStatus %5D =&RuleModel%5BRuleId%5D” – cindy 2011-02-22 22:37:22