0

MVC4 Web アプリケーションで Ajax を使用しています。アクション メソッドに値を渡すときに問題が発生しました。パラメータ値として常に null を渡します。これが私のコードです。

    function onChange(arg) {
    var adrId = $.map(this.select(), function (item)
    {
        return $(item).find('td').first().text();
    });

      GetEntries(adrId);//Calling the function

    }

function GetEntries(adrId) {

    //alert("AdrId >> "+adrId); here it shows value is 3465

    $.ajax({
        url: 'Customer/LoadCustomer',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({ adrId: adrId }),
        success: function (result) {
            alert("success");
        }
    });
} 


    [HttpPost]
    public JsonResult LoadCustomer(string adrId)//HERE value is ALLWAYS NULL.. :(
    {
        Address_SelectW adrList = new Address_SelectW();
        adrList = this.commonObj.CustomersSelectByAdrKy(cky, usrKy, AdrKy);
        return Json(adrList, JsonRequestBehavior.AllowGet);
    }

この問題を解決するのを手伝ってください。ありがとうございました.. :)

================================================== ========================= 追加情報....

別のものを使用してデータを挿入しました。それはうまくいきました..

 $("#btnSave").click(function () {

    //var ContactID = $("#txtContactId").val();
    var Company = $("#txtCompany").val();
    var Status = $("#cmbStatus").val();
    var IsActive = $("#IsActive").is(':checked');
    var Comments = $("#txaComments").val();
    var Country = $("#cmbCountry").val();
    var Address1 = $("#txtAddress1").val();
    //var Address2 = $("#txtAddress2").val();
    var City = $("#txtCity").val();
    var State = $("#txtState").val();
    var PostalCode = $("#txtPostalCode").val();
    var VatNo = $("#txtVatNo").val();
    var RegNo = $("#txtRegNo").val();
    var Phone = $("#txtPhone").val();
    var Email = $("#txtEmail").val();
    var AdrKey = $("#AdrID").val();


    $.ajax({
        url: "Customer/InsertCustomer",
        data: {
            //'ContactID': ContactID,
            'Company': Company,
            'Status': Status,
            'IsActive': IsActive,
            'Comments': Comments,
            'Country': Country,
            'Address1': Address1,
            //'Address2': Address2,
            'City': City,
            'State': State,
            'PostalCode': PostalCode,
            'VatNo': VatNo,
            'RegNo': RegNo,
            'Phone': Phone,
            'Email': Email
        },
        dataType: "json",
        type: 'POST',
        success: function (data) {
            alert("Successfully Inserted!");
        },
        error: function () {
            alert("error");
        }
    });


});



    [HttpPost]
    public ActionResult InsertCustomer(string Company, int Status, bool IsActive, string Comments, int Country, string Address1, string City, string State, string PostalCode, string VatNo, string RegNo, string Phone, string Email)
    {
        AdrCustomModel model = new AdrCustomModel();
        bool process = false;

        model.Company = Company;
        model.Status = Status;
        model.IsActive = IsActive;
        model.Comments = Comments;
        model.Country = Country;
        model.Address1 = Address1;
        model.City = City;
        model.State = State;
        model.PostalCode = PostalCode;
        model.VatNo = VatNo;
        model.Phone = Phone;
        model.RegNo = RegNo;
        model.Email = Email;
        model.cky = cky;

        model.ContactID = this.CustomerID(Status);

        process = this.commonObj.InsertAdrCustomer(model,usrKy);

        Accounts_Select accmodel = new Accounts_Select();
        accmodel.CKy = cky;
        accmodel.AccCd = model.ContactID;
        accmodel.AccNm = Company;
        accmodel.AccTypKy = this.commonObj.AccTypeKyByPrefixKy(Status);

        process = this.commonObj.InsertAccount(accmodel, usrKy);

        return Json(process, JsonRequestBehavior.AllowGet);
    }

なぜこれがうまく機能していて、それが機能していないのか、私にはわかりません。JsonResultActionResultの両方を Action メソッドに試しました。また、[HttpPost]の有無にかかわらず試してみました。ただし、常にパラメーター値は NULL です

4

4 に答える 4