【问题标题】:Endpoint Not found MVC端点未找到 MVC
【发布时间】:2020-09-17 02:41:35
【问题描述】:

我正在使用一个非常奇怪的端点, 现在我发布到我的端点的数据是scorecardIdDashboardConfig,我的其余数据是通过后端填充的,即UserIdDateCreated,现在我需要做一个获取请求对于特定用户,我做了这样的事情:

#region Public Methods
        [HttpGet]
        [Route("GetbyUserID")]
        [ValidateModel]
        public IHttpActionResult GetbyUserID(Guid UserID)
        {
            UserID = this.GetUserId();
            var config = _prefentialDashboardConfigService.GetByUserID(UserID);
            return Ok(config);
        }

我的模特:

    public Guid ScorecardId { get; set; }

    public Guid UserId { get; set; }

    public DateTime DateCreated { get; set; }

    public string DashboardConfig { get; set; }

我的 CRUD:

        public PrefentialDashboardConfig GetByUserID(System.Guid UserId, params string[] includes)
    {
        return Repository.SingleOrDefault<PrefentialDashboardConfig>(config => config.UserId == UserId, includes);
    }
}

我的 ICRUD:

        T SingleOrDefault<T>(Expression<Func<T, bool>> where, params string[] includes) where T : class;

在我的前端,我只是调用了 get 请求,但它给了我一个 404 resource not found 错误。我在淘汰赛中这样称呼我的终点:

var test = PreferentialProcurementDashboardApi.GetbyUserID();
//For testing purposes
console.log("You got it right!" + JSON.stringify(test));

通过从后端获取的 UserId 将我的数据发送到前端控制台的最佳方式是什么?

【问题讨论】:

    标签: asp.net-mvc knockout.js


    【解决方案1】:

    只是猜测,您在执行 http get 请求时可能没有传递 UserId。

    var test = PreferentialProcurementDashboardApi.GetbyUserID();
    

    应该是

    var test = PreferentialProcurementDashboardApi.GetbyUserID(5);
    

    检查浏览器开发工具中的网络选项卡,确保有参数被传递到后端

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-06
      • 2018-02-15
      • 2020-04-14
      • 1970-01-01
      相关资源
      最近更新 更多