Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 在asp.net mvc3中筛选结果集_Asp.net Mvc 3_Linq - Fatal编程技术网

Asp.net mvc 3 在asp.net mvc3中筛选结果集

Asp.net mvc 3 在asp.net mvc3中筛选结果集,asp.net-mvc-3,linq,Asp.net Mvc 3,Linq,我有一个IEnumerable视图。这个视图页面包含一个模型数据和一个表单的一些数据。它列出了数据库中我的模型的所有数据。我想通过多个筛选选项筛选这些数据,例如按城市、区域、楼层、道路编号e.t.c筛选所有这些筛选都在我的表单字段中。我的操作如下: 我的查看页面: 我的所有过滤器选项是可选的。可以选择一个或多个过滤器选项,也可以不选择其中任何一个。它给出了错误范围变量POST,我想在每个if条件块中过滤我的结果集。可能吗???如果可能的话,请给我一些想法。。。。。提前感谢在运行查询之前,最

我有一个IEnumerable视图。这个视图页面包含一个模型数据和一个表单的一些数据。它列出了数据库中我的模型的所有数据。我想通过多个筛选选项筛选这些数据,例如按城市、区域、楼层、道路编号e.t.c筛选所有这些筛选都在我的表单字段中。我的操作如下:

我的查看页面:


我的所有过滤器选项是可选的。可以选择一个或多个过滤器选项,也可以不选择其中任何一个。它给出了错误范围变量POST,我想在每个if条件块中过滤我的结果集。可能吗???如果可能的话,请给我一些想法。。。。。提前感谢

在运行查询之前,最好先检查结果是否为null&&Any。筛选器1和/或2可能会排除所有您需要的结果

if (Request.Form["searchString"] != null)          
{
    if ((posts!=null) && (posts.Any()))
         {
                posts = (from posts in db.posts where posts.area
                ==Request .Form["searchString"]).ToList();                                
         }
}           
if (Request.Form["searchString2"] != null)          
{              
    if ((posts!=null) && (posts.Any()))   
         {
                posts = (from posts in db.posts where posts.area
                ==Request .Form["searchString2"]).ToList();                                
         }
}            
if (Request.Form["searchString3"] != null)          
{
    if ((posts!=null) && (posts.Any()))   
         {
                posts = (from posts in db.posts where posts.area
                ==Request .Form["searchString3"]).ToList();                                
         }
}              

您能更具体地说明错误消息吗?它给出了错误:范围变量“posts”与先前的posts声明冲突。我认为这个错误只适用于Var帖子……我明白了……然后我会将您的Var重命名为其他内容。也许这是个难题,你不需要打字。var根据等式的右边为您计算出它。然而,它看起来就像是IListhave,你是否将posts重命名为posts1只是为了看看会发生什么
   @using (Html.BeginForm()){   
     <p> Area: @Html.TextBox("SearchString") 
     <p> City: @Html.TextBox("SearchString2") 
     <p> Floor: @Html.TextBox("SearchString3") 
     <input type="submit" value="Filter" /></p>
    }


   >.....list of Model Data
if (Request.Form["searchString"] != null)          
{
    if ((posts!=null) && (posts.Any()))
         {
                posts = (from posts in db.posts where posts.area
                ==Request .Form["searchString"]).ToList();                                
         }
}           
if (Request.Form["searchString2"] != null)          
{              
    if ((posts!=null) && (posts.Any()))   
         {
                posts = (from posts in db.posts where posts.area
                ==Request .Form["searchString2"]).ToList();                                
         }
}            
if (Request.Form["searchString3"] != null)          
{
    if ((posts!=null) && (posts.Any()))   
         {
                posts = (from posts in db.posts where posts.area
                ==Request .Form["searchString3"]).ToList();                                
         }
}