0

I have created a popup in which there is a textbox and a bunch of checkboxes. I have given all the checkboxes a value and these values are stored in an array. Now i want to pass this array and textbox value from Jquery to controller action. How can i do this ? I have tried on stackoverflow by all the keywords, but it doesn't work...

My jquery data is as follws:

$("#submit-button").click(function () {
    var AccessBit = new Array(7);
    AccessBit = BitLogic();  // integer array returned from BitLogic method
    var role = $("#RoleName").val();  // Textbox value
    var json = JSON.stringify(AccessBit);
    alert(AccessBit);
    $.ajax({
        url: "/Role/BitLogic",
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: json,

        dataType: 'json',
        success: function (data) {
            console.log(data);
            window.location.reload(true);
        }
    });

    $("#createForm").dialog("close");
});

and Controller is as follows:

[HttpPost]
public void BitLogic(int[][] AccessBit)
{

} 

How can i pass role value along with Accesbit array ? AccessBit is two dimensional integer array.

7
  • Is you array successfully passed to controller ? Commented Sep 4, 2014 at 5:14
  • yes my array is successfully passed to controller in this way... Commented Sep 4, 2014 at 5:17
  • AccessBit ? show the code of accessbit Commented Sep 4, 2014 at 5:17
  • AccessBit has a quite complex structure... u can't understand without full description... and I am receiving AccesBit array as i want... The main concern is how pass to pass Accesbit along with RoleName to Controller Commented Sep 4, 2014 at 5:18
  • Create a second parameter in you post method (say string role) and include in your ajax data parameter Commented Sep 4, 2014 at 5:19

1 Answer 1

2

Add an additional parameter in you POST method

[HttpPost]
public void BitLogic(int[][] AccessBit, string role)
{
  ....
}

Then pass the value in your ajax function

$.ajax({
  .....
  data: JSON.stringify({ AccessBit: AccessBit, role: role }),

Credit also to Mairaj Ahmad

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.