我在局部视图中有这个:
<script type="text/javascript">
var jqxhr = $.getJSON("<%= Url.Action("GetTrainingModulePoints" , "Home") %>", function (data) {
console.log(data.id);
});
</script>
HomeController中:
[HttpGet]
public JsonResult GetTrainingModulePoints()
{
var currentUser = ZincService.GetUserForId(CurrentUser.UserId);
ZincService.TrainingService.GetTrainingModulePoints(currentUser.UserId);
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
GetTrainingModulePoints方法位于根控制器目录中的HomeController中。 我收到500内部服务器错误,所以它没有找到它。我的Url.Action出了什么问题?
请帮帮忙? 感谢
答案 0 :(得分:1)
您正在使用Url帮助程序生成控制器操作的URL。但是您将状态代码500与404混淆。状态代码500表示内部服务器错误。例如,如果在控制器操作中抛出异常,则可能导致此错误。
ZincService.GetUserForId
和ZincService.TrainingService.GetTrainingModulePoints
是此例外的理想候选人。
如果您在浏览器中使用javascript调试工具(例如FireBug或Chrome开发人员工具栏),您可以检查网络选项卡,您将在其中看到AJAX请求的确切请求/响应。通过查看响应,您可以获得有关错误原因的更多信息。