Your basic issue is that you are pushing the data payload as items on the querystring, not as a JSON payload. In this scenario the QueryString value provider will be responsible for populating the method's parameters.
All querystring key values are treated as an array by the provider. If you specify a data type and the key's value has 1 entry then the provider will flatten the array to a single value.
In your case you specify an object
datatype, so the provider gives you the array of 1 entry.
To fix this you need to switch from $.get to $.ajax, supply a few extra parameters and force the data payload to be a JSON string.
$.ajax({
url: "MyController/GetComponent",
type: 'POST',
contentType: 'application/json',
dataType: 'JSON'
data: JSON.stringify(
{
compClasskey: component.FullCode(),
compValue: component.Value()
})
});
The MVC application should now use the JSON value provider ( as the contentType is now changed to application/json
) instead of the QueryString provider and the compValue parameter will now set as you expect.
As an aside: IMHO you should NEVER request a JSON document via a GET request, it is still an attack vector, unless you can 100% guarantee IE10+, Chrome 27+ or Firefox 21+.