Reputation: 3110
I'm working on my first ASP.net MVC apps, in this apps i got to type of search Simple and Advanced :
Simple search olny dd,df and gov are required
Advanced search user got more options, even in advanced search dd,df and gov are required field.
So this is my Search Action
[HttpPost]
public ActionResult search(LogModel.Search soption)
{
// this part will not change the same in simple and advenced
DateTime dd1 = soption.dd;
DateTime df1 = soption.df;
var model = (from p in entity.vehicule
where p.agence.idgov == soption.gov
where !p.indisponible.Any(b => (dd1 >= b.Dd && dd1 <= b.Df) || (df1 >= b.Dd && df1 <= b.Df))
where !p.indisponible.Any(c => (c.Dd >= dd1 && c.Dd <= df1) || (c.Df >= dd1 && c.Df <= df1))
select p).ToList();
// here i want to add my filtring action advanced search
if (!soption.mark)
model = model.Any(b => b.idmarque == soption.mark );
return View(model);
}
the simple search mode work so fine but now i'm trying to implement the advanced search and this is what i got in my mind :
If model.myVar is not null(that mean user has puted something )
then i'm gonna filter some result from my pricinple model search request.
So I'm wondring if i got right ? also this line is underlined with red :
model = model.Any(b => b.idmarque == soption.mark );
Impossible to convert type bool to Systeme.collection.generic.list
Upvotes: 0
Views: 474
Reputation: 8920
Just use a where clause again
if (!soption.mark)
model = from x in model
where (b => b.idmarque == soption.mark )
select x
Upvotes: 1