0

I have an Ajax call as below from my client js files to an MVC acontroller method

From the client js files ::

var ActivityLog = new Array();
var Test={}
Test['Customer[0].Id'] = "3060_3";
Test['Customer[0].Value'] = "0";
Test['CustId'] = "1111";
Test['crl'] = true;
Test['ActNumber'] = "2222";

for (var i = 0; i < 2; i++) {
    Test['ActivityLog[' + i + ']'] ="1";
}

My Controller ActionMethod ::

 public ActionResult SaveAccountCustomerServicePlans(string CustId, IDictionary<string, Customer> Customer, bool? crl, string ActNumber, string[] ActivityLog)
{
   // Here all the parameter i am getting as null
}

My entity class

public class Customer
    {
    [DataMember]
    [Key]
    public int Id{ get; set; }


    [DataMember]
    public string Value{ get; set; }



} 

My Ajax call::

$.ajax({
        type: 'POST',

        async: true,
    });

    $.ajax({
   beforeSend: function (xhr) {
       xhr.setRequestHeader('__RequestVerificationToken', $(':input:hidden[name*="RequestVerificationToken"]').val());
   },
   type: "POST", url: "Customerss/Customermanagement/SaveAccountCustomerServicePlans", data: { Test: Test},
   success: function (data) {
       /////
   }
});

In above controller method all the parameters i am getting as null . But aif i remove ActivityLog from Test object everything works fine . Can anybody please help me to solve this issue.

2 Answers 2

1

try with this,

change your controller

    public ActionResult SaveAccountCustomerServicePlans(Customer model, string CustId, bool? crl, string ActNumber, List<string> ActivityLog)
    {

then in the javascript

    var ActivityLog = new Array();
    var Test = {}
    Test['Id'] = "30603";
    Test['Value'] = "0";
    Test['CustId'] = "1111";
    Test['crl'] = true;
    Test['ActNumber'] = "2222";

    for (var i = 0; i < 2; i++) {
        Test['ActivityLog[' + i + ']'] = "1";
    }

and finally in your ajax

  type: "POST", url: "Customerss/Customermanagement/SaveAccountCustomerServicePlans", data: Test,

Hope this help you

Note: in your Model class you have Id like "int" but in the javascript you are sending a string "30603_3";

Sign up to request clarification or add additional context in comments.

Comments

0

remove the plus before i like below not sure why its there

Test['ActivityLog['  i + ']'] ="1";

or remove the plus all together if you trying to save the ="1" there like below

Test['ActivityLog[' i ']'] ="1";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.