クライアント側に、SettingName プロパティと SettingValue プロパティを持つ JavaScript オブジェクトがあります。
データ例 -
obj1.SettingName = "createdDate";
obj1.SettingValue = "10/07/2013";
obj2.SettingName = "arrayOfNames";
obj1.SettingValue = SomeArray; //An array of 5 strings
var settingsArray =new Array();
settingsArray[0] = obj1;
settingsArray[1] = obj2;
var settingsContainer = new Object;
settingsContainer.Settings = settingsArray;
ajax 呼び出し -
$.ajax({
type: "POST",
url: "myURL",
data: { settings: JSON.stringify(settingsContainer)},
dataType: 'json',
success: function (data) {
//do something
}
});
サーバー側クラス -
public class Setting
{
public string SettingName { get; set; }
public object SettingValue { get; set; } //so this can hold multiple data types
}
public class SettingsContainer
{
public List<Setting> Settings { get; set;}
}
コントローラーアクション -
public ActionResult myURL(SettingsContainer settings) {
//Here, the value for SettingsContainer.Settings[1].SettingValue, which
should be Array[5] i.e. on the C# side, I expect to see Object[5],
is only {object}. I'm not sure what's going on.
Is my approach of handling this correct?
}
アドバイス/ヘルプをいただければ幸いです。ありがとうございました!