I just want to know why it's necessary for .NET to match parameter name with the JSON object's key name?
Quick code preview here...
var json = {
"service": "COMMON",
"method": "MENU_SUBLIST",
"UID": "1000007",
"ULID": "stackoverflow",
"UNM": "queston",
"SITE": "1",
"DEPT": "2",
"LANG": "ko",
"MENUID": "0000",
"STEPMENU": "",
"ACTIONNAME": ""
}
Okay, Let's call an action in a controller through Ajax.
$.ajax({
type: "POST",
url: "DATACRUD.json",
data: JSON.stringify(json),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false, //_async,
success: function (result) {
}
});
And my c# action code here..
[HttpPost]
public ActionResult DATACRUD(string jsondata)
{
return Json(new{ fromMVC = jsondata});
}
// Just example.
jsondata is here null because I didn't match the key name.
For DATACRUD to get the JSON data, I have to do like this.
{ jsondata : {
"service":"COMMON",
"method":"MENU_SUBLIST",
"UID":"1000007",
"ULID":"stackoverflow",
"UNM":"queston",
"SITE":"1",
"DEPT":"2",
"LANG":"ko",
"MENUID":"0000",
"STEPMENU":"",
"ACTIONNAME":""
}
}
Here question No.1 Why do I have to match the key name with the param name?
It just does? there's gotta be a reason, and I want to know why.
And what I want to do is...
{
"service":"COMMON",
"method":"MENU_SUBLIST",
"UID":"1000007",
"ULID":"stackoverflow",
"UNM":"queston",
"SITE":"1",
"DEPT":"2",
"LANG":"ko",
"MENUID":"0000",
"STEPMENU":"",
"ACTIONNAME":""
}
to pass this JSON data into the action, DATACRUD I specified above
I want DATACRUD action to take the JSON data and consume it whatever the key name is.
There's another answer for this. The answer is to create a model for JSON data and receive it as a model type, and get the model as string.
But defining models cannot be possible in my apps. It could cause a hundred of model creation.
So receiving the JSON data after making a model is the last thing I need.
In this case, how am I supposed to do?
No key name matching is allowed.
No generating model is allowed.
No third party framework is allowed.
I think the possible answers narrow down to a few....
What I have to do?