简体   繁体   English

在ajax调用中传递多个参数

[英]Passing multiple parameters in ajax call

I am having having problem with sending the an object and two parameter in an ajax call. 我在ajax调用中发送对象和两个参数时遇到问题。

My Server side method: 我的服务器端方法:

public ActionResult AddUpdate(string model, bool IsEdit, string Type)
{
//Do something
}

Client side ajax call is: I am fetching all form values provided by user and saving them into "MemberObj" and sending another 2 parameters ie IsEdit and Type. 客户端ajax调用是:我正在获取用户提供的所有表单值,并将它们保存到“ MemberObj”中,并发送另外两个参数,即IsEdit和Type。 but at server side i am getting only the IsEdit and Type values model parameter is null. 但是在服务器端,我仅得到IsEdit和Type值模型参数为null。 The date value in ajax call after stringify is like: 字符串化后,ajax调用中的日期值类似于:

"{"model":{"id":"123","Name":"Jhon Doe","Relation":"Father","Dob":"15-3-2014","Address":"abc":" abc","City":"abc","MobileNumber":"1234567890"},"IsEdit":false,"Type":"FamilyMember"}"


var MemberObj={};
MemberObj.Name="aaa";
var requestJSONData={ "model": MemberObj, "IsEdit": IsEdit, "Type": str[0] }
$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        url: '/Employee/AddUpdate',
        data: JSON.stringify(requestJSONData)
        success: function (msg) {
            //Success
        },
        error: function (msg) {

        }
    });

Any help is most appericiate. 任何帮助都是最合适的。 Thanks 谢谢

in one of my projects i used the following line and it works like a charm: 在我的一个项目中,我使用了以下代码,它就像一个符咒:

  data: "{'sid':'" + sid.toString() + "'}",

try adapting yours to this format, it should work. 尝试使您的格式适应这种格式,它应该可以工作。

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

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