繁体   English   中英

需要使用 ajax 帖子将对象列表和其他 object 发送到 controller

[英]Need to send list of objects and other object to controller using ajax post

需要使用 Z2705A83A5A0659CDACE3458397267 方法将 object 和其他 object 列表发送到 controller。 当我尝试使用 ajax 发布方法使用视图 model 发送时,请始终列出 null。 下面是代码。 JavaScript 代码:

function SubmitForm() {        
    var ServiceDefinition = $("#frmService").serialize();
    var clinicServiceList = [];
    $(".chkUserLocation:checked").each(function () {                   
        var checkBoxId = $(this).prop("id");
        checkBoxId = "#accordion" + checkBoxId;
        var emergencyPrice = $(checkBoxId).find(".clsEmergencyPrice").val();
        var opdPrice = $(checkBoxId).find(".clsOpdPrice").val();
        var ipdPrice = $(checkBoxId).find(".clsIPDPrice").val();
        var statPrice = $(checkBoxId).find(".clsStatPrice").val();
        var clinicServiceId = $(checkBoxId).find(".hdnClinicServiceId").val();
        clinicServiceList.push({
            'OpdPrice': opdPrice,
            'IpdPrice': ipdPrice,
            'ERPrice': emergencyPrice,
            'StatPrice': statPrice,
            'LocationId': $(this).prop("id"),
            'ClinicServiceId': clinicServiceId
        });            
    });
    var data1 = { 'clinicServices': clinicServiceList };
    var data = JSON.stringify(data1);
    var serviceDefination = { 'ServiceDefinition': ServiceDefinition };
    var serviceViewModel = {
        'ServiceDefinition': ServiceDefinition,
        'clinicServices': JSON.stringify(clinicServiceList)
    }
    $.ajax({
        url: '@Url.Action("ServiceForm", "Service")',
        type: "POST",
        dataType: "json",
        contentType: 'application/json; charset=utf-8',
        data: serviceViewModel,
        async: true,
        success: function (msg) {
          
        },
        error: function (result) {
          
        }
    });  
}

Controller 代码:

public ActionResult ServiceForm(ClinicServiceViewModel serviceViewModel)
{
    return json(result);
}

Model 代码:

    public class ClinicServiceViewModel 
{
    public ClinicServiceViewModel()
    {
        ServiceDefinition = new ServiceDefinition();
        ClinicServices = new List<ClinicService>();
    }
    public ServiceDefinition ServiceDefinition { get; set; }
    public List<ClinicService> ClinicServices { get; set; }

}

任何一个指导我犯错的地方?

请试试:

var serviceViewModel = { 'ServiceDefinition': ServiceDefinition, 'clinicServices': ClinicServiceList }

数据:JSON.stringify(serviceViewModel),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM