访问Url.Action在该项目的根控制器 [英] Accessing Url.Action in a root controller of the project

查看:153
本文介绍了访问Url.Action在该项目的根控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这在我的部分观点:

i have this in my partial view:

<script type="text/javascript">
   var jqxhr = $.getJSON("<%= Url.Action("GetTrainingModulePoints" , "Home") %>", function (data) {
      console.log(data.id);
   });
</script> 

HomeController的:

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?

the GetTrainingModulePoints method is in the HomeController in the root controller directory. I get an 500 Internal Server Error, so it is not finding it. What is wrong with my Url.Action?

请帮忙?
谢谢

please help? thanks

推荐答案

您是否正确使用URL帮手生成的URL控制器动作。但你困惑状态code 500与404状态code 500指内部服务器错误。此错误可能例如,如果有异常的控制器动作里面抛出造成的。

You are correctly using an Url helper to generate the url to the controller action. But you are confusing status code 500 with 404. Status code 500 means Internal Server error. This error could be caused for example if an exception is thrown inside your controller action.

ZincService.GetUserForId ZincService.TrainingService.GetTrainingModulePoints 是此异常好的候选人。

The ZincService.GetUserForId and ZincService.TrainingService.GetTrainingModulePoints are good candidates for this exception.

如果您在浏览器中使用JavaScript调试工具(如萤火虫或Chrome开发者工具栏)您可以检查网络选项卡,在这里您将看到AJAX请求确切的请求/响应。通过查看响应你可能会得到关于此错误的原因的更多信息。

If you use a javascript debugging tool in your browser (such as FireBug or Chrome developer toolbar) you can inspect the Network tab where you will see the exact request/response for the AJAX request. By looking at the response you might get more information about the reason for the error.

这篇关于访问Url.Action在该项目的根控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆