I have an javascript array like this:
var optionArray = new Array();
optionArray["totalBankAmount"] = $("#totalBankAmountID").val();
optionArray["singlePlayerAmount"] = $("#singlePlayerAmountID").val();
..... (more array data)
I am sending this Array like this into StartOption (a MVC3 Controller):
$.ajax({
url: "/StartOption/Index/",
data: { allOptions: JSON.stringify(optionArray) },
cache: false,
type: "POST",
timeout: 10000,
dataType: "json",
success: function (result) {
....
}
});
How Index Action will catch that optionArray ? how i get those data by there array index name into my Index action ?
Please give me a good example, I am new in MVC3.
and sorry for my bad English.
No, you don’t have an array. Arrays in javascript must have zero based integer indexes. What you have is a javascript object.
So there are 2 scenarios:
Let’s cover the objects scenario first. So you have an object:
and then you want to pass it to a controller action:
here’s how the calling code might look like:
And the second case, with arrays:
and the calling code: