1
當我從Ajax調用收到JSON數據,我的型號是空:MVC3 - 傳遞的Json模型控制器(詞典)
這是我在C#模式:
public class ErrorReportModel
{
public bool isSuccess { get; set; }
public Dictionary<string, ScriptExecResultEntity[]> Errors{get;set;}
}
這是我的AJAX調用:
StringJsonLastExecutionReportModel = JSON.stringify(JsonLastExecutionReportModel);
$.ajax({
url: urlPath,
type: 'POST',
dataType: 'html',
data: StringJsonLastExecutionReportModel,
contentType: 'application/json; charset=utf-8',
success: function (data, status, xhr) {
},
error: function (xhr, status, error) {
alert(error);
}
});
JSON數據(StringJsonLastExecutionReportModel
)看起來是這樣的,它是有效的:
{
"isSuccess": false,
"Errors": {
"e794bfa7-657b-482c-acdf-c5a3b6d2ce83": [
{
"ErrorMsg": "Invalid object name 'asfasf.CONTACT'.",
"Id": "63755f2a-1f02-480e-ab94-cafc62fd9634",
"ScriptContent": "CREATE VIEW [asfasf].Blala AS select * from [asfasf].[CONTACT]",
"ScriptDescription": "Script 6",
"ServerType": "SQLSERVER",
"Success": false
}
]
}
}
這裏是我的控制器的方法:
public void DisplayErrorsReportAsync(ErrorReportModel model)
{
AsyncManager.Parameters["ErrorReportModelObject"] = model;
}
接收模式是這樣的:
爲什麼我在我的字典裏的值對象是空?
什麼是jQuery的簽名.ajax()函數,以字符串而不是json傳遞對象。因爲現在我收到來自ajax調用的字符串對象作爲空 – billybob
改變你的控制器方法,而不是模型放'字符串模型'然後接受它作爲字符串 – Nilesh
我做了,但它不工作。我收到它爲空。 – billybob