我的动作是:动作总是返回null
[HttpPost]
public ViewResult SearchPost(FormCollection frm)
{
IList <post> p =db.posts.Include("user").ToList();
if (Request.Form["area"] != null)
{
if ((p!=null) && (p.Any()))
{
p =p.Where(a=>a.area==Request.Form["area"]).ToList();
}
}
if (Request.Form["floor"] != null)
{
if ((p!=null) && (p.Any()))
{
p = p.Where(a => a.floor ==
Request.Form["floor"]).ToList();
}
}
if (Request.Form["garage"] != null)
{
if ((p!=null) && (p.Any()))
{
p = p.Where(a => a.garage ==
Request.Form["garage"]).ToList();
}
}
return View(p);
}
它没有表现出任何差错。但总是返回null。它应该返回过滤后的对象或简单所有帖子而不进行过滤。有什么问题吗 ??我找不到它。
我看不出这可能会返回视图数据'null';每个路径都分配有'p'。它可能是一个空列表,但不是'null'。那么你的意思是别的吗? –
是db.posts.Include(“user”)。ToList()总是空?这是我能看到它的唯一方法将返回null。 – Gage
@Gage'ToList'永远不会返回null。除非他们定义了他们自己的ToList,这看起来不太可能 –