控制器內部服務器錯誤#500,而試圖用jQuery Ajax和MVC
public JsonResult TeamInfo(string teamName)
{
teamDA = new TeamDataAccess();
var teamInfo = teamDA.TeamInfo(teamName);
System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
new System.Web.Script.Serialization.JavaScriptSerializer();
string sJSON = oSerializer.Serialize(teamInfo);
JsonResult jsonResult
=new JsonResult(){ JsonRequestBehavior = JsonRequestBehavior.AllowGet };
jsonResult.Data = sJSON; // first i give this.
jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return jsonResult;
}
調用從jQuery的
$.ajax({
url: 'Team/TeamInfo/' + teamName,
success: function (data) {
$('#teamDetails').html(data);
alert('Load was performed.');
$("#dialog-modal").dialog("open");
}
});
控制器顯示JSONResult在調試,我可以看到它正在執行到最後line in controller return jsonResult;
但不可見alert('Load was performed.');
。 你知道它沒有進入成功部分的原因是什麼?服務器端沒有錯誤。任何幫助,高度讚賞。
編輯 當我在ajax調用中添加error
。它說錯誤500(內部服務器錯誤)。我如何找到這個問題?
你爲什麼發回'JsonResult'如果直接把結果頁面的DOM爲HTML?嘗試註釋'$('#teamDetails')。html(data);'....看看會發生什麼。 – nemesv 2012-07-11 14:11:28
什麼都沒有。它只是完成了控制器的功能,並沒有進入成功。有沒有必要添加我的代碼? – kbvishnu 2012-07-11 14:16:43
從瀏覽器調用您的操作,而不是通過ajax調用。服務器將爲您返回錯誤頁面。或者以調試模式運行。 – devundef 2012-07-11 14:30:58