Can I attach an array of ints to a Json object and pass to controller method?
Basically what I do here is pass a couple string values attached to a Json object to an MVC controller method, and this method takes those parameters with it's input params and does something with them. Just the names of the paramaters have to match up and I can use then, similar to direct MVC routing...
I want to use this same method to create a grid in memory with MSChart. However, I want to pass arrays of values to the controller through Json so I can create a grid from those values.
Can I do that? and how?
Here is the code I already have for the prior reason:
function showAnalysisView(analysisType)
{
var typeJSON = {};
typeJSON["id"] = GetGUIDValue();
typeJSON["value"] = analysisType;
$.ajax({
type: "POST",
url: "<%= Url.Action("AnalysisNavigation", "Indications") %> ",
dataType: "jsonData",
data: typeJSON,
success: function(data) {
if (analysisType == 'Prepayment') {
开发者_JAVA技巧 document.getElementById('prepaymentView').innerHTML = "";
$("#prepaymentView").append(data);
}
else if (analysisType == 'Exposure') {
document.getElementById('exposureView').innerHTML = "";
$("#exposureView").append(data);
}
}
});
}
Can I have instead of :
typeJSON["value"] = analysisType;
Something like:
typeJSON["xArray"] = {0,1,2,3,4,5};
and then read it with my controller like:
public System.Web.Mvc.ActionResult MakeGrid(int[] values)
{
}
Thanks!
I think what you want is
typeJSON = {
key: 'existing value',
key2: 'existing value2',
newChartData: [1,4,5,3,4,3,5,4]
}
Your existing values are still in the object, and you add a third one for your new array. JSON serializes arrays just fine
You can't do
typeJSON["xArray"] = {0,1,2,3,4,5};
But you can do
typeJSON["xArray"] = {0:0, 1:1, 10:2, 'key':'value', 'someKey':3, 7:'someValue'};
Basicly you need to enter key:value
pairs , not just value
, then it's just a matter of reading the values you recive in you're app .
精彩评论