存储方法的500内部服务器错误

时间:2017-02-07 23:09:49

标签: c# angularjs asp.net-mvc

我在控制器内部获得了一个空引用异常:

返回等待Store.GetSearchDTO();

控制台中的错误显示为:

POST http://localhost:55471/api/GetSearchDTO 500(内部服务器错误)

错误:解决失败的原因为[object Object],但没有为细分resolveFailed提供Search

任何关于为什么会发生这种情况的见解都会很棒。

控制器

namespace Api.Controllers
{
    [Authorize]
    [RoutePrefix("api/Search")]
    public class Controller : ApiController
    {

        private Store _store;

        public Store Store
        {
            get
            {
                return _store ?? Request.GetOwinContext().Get<Store>();
            }
            private set
            {
                _store = value;
            }
        }
        public Controller()
        {

        }
        public Controller(Store store)
        {
            Store = store;
        }
        [HttpPost]
        [Route("GetSearchDTO")]
        public async Task<SearchDTO> GetSearchDTO()
        {
            return await Store.GetSearchDTO();
        }
    }
}

存储

        public async Task<SearchDTO> GetSearchDTO()
        {
            var toReturn = new SearchDTO();
            var assessment = await Db.Definitions.Where(x => x.IsActive == true).ToListAsync();
            var Types = await Db.Types.ToListAsync();
            int i = 0;
            int j = 0;
            foreach(var assess in assessment)
            {
                var courseName = await Db.Courses.Where(x => x.Id == assess.CourseId).FirstOrDefaultAsync();
                toReturn.CourseIds[i] = courseName.Id;
                toReturn.CourseNames[i] = courseName.Name;
                toReturn.Names[i] = assess.Name;
                i++;
            }
            foreach(var type in Types)
            {
                toReturn.TypeIds[j] = type.Id;
                toReturn.Types[j] = type.Name;
            }

            toReturn.SectionFlag = true;

            return toReturn;
        }
    }

}

0 个答案:

没有答案