【发布时间】:2018-06-12 22:12:33
【问题描述】:
这是我的代码:
[HttpGet]
public ActionResult GetCategor(int catId)
{
using (uuEntities ems = new uuEntities())
{
return Json(ems.SupportSubCats.Where(x => x.CatID == catId).Select(
x => new
{
SubId = x.SubCatID,
SUbName = x.SubCatName
}).ToList(), JsonRequestBehavior.AllowGet);
}
}
我尝试过的:
在控制器中:
[HttpGet]
public ActionResult GetCategor(int catId)
{
return Json(_service.List(int catId), JsonRequestBehavior.AllowGet);
}
}
服务中:
public void List(int catId)
{
return new GenericRepository<SupportSubCategory>(_factory.ContextFactory)
.Get(filter: (x => x.CatID == catId))
.Select(x => new
{
SubId = x.SubCatID,
SUbName = x.SubCatName
}).ToList();
}
我认为我的返回类型不正确,请建议我解决方案。在公共 void 附近,我收到 void 无法返回列表的错误。
【问题讨论】:
标签: .net model-view-controller service