-2

i am having one array in javascript named as checkboxarray which contain some elements which is dynamic.

now i want to pass this array to controller through java script.

my controller name is Test and action name is Questionbank.

can any one tell me how to pass this array to controller?

I have tried through ajax but value is coming null at controller.

3
  • 2
    Please include the relevant code. Otherwise debugging it is job for a crystal ball, not a programmer. :-)
    – Palec
    Commented Jul 7, 2014 at 10:44
  • you can use ajax to send array in the data parameter
    – Rajesh
    Commented Jul 7, 2014 at 10:46
  • can u show me thorugh code for how to passthroguh ajax Commented Jul 7, 2014 at 10:58

1 Answer 1

0

You can use JSON.stringify when you posting data to pass arry of objects to controller.

$.ajax(
{
    url: 'Test/Questionbank',
    data: JSON.stringify({checkboxarray  : checkboxarray }),
    contentType: 'application/json',
    dataType: 'json',
    type: 'POST',
    success: function (data) {
        alert("success");
    },
    error: function () { alert('error');}
});

Please refer following post for more information.

Pass Complex JavaScript Object to MVC Controller

It illustrates how we can pass complex javascript objects to MVC controller.

Thanks !

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.