I have a controller action that uses PredicateBuilder to build a dynamic linq query. I want to pass the results of this query to a partial view. What is the best way to do this? If it's best practice to always use strongly typed views, should my view model that I pass to the controller action have a list that I can pass the results of the query into? Or is this just extra overhead using two lists?
Here's a simplified version of the controller action:
[HttpPost]
public ActionResult BasicPropertySearch(BasicPropertySearchViewModel viewModel)
{
var predicate = PredicateBuilder.True<ResidentialProperty>();
if (ModelState.IsValid)
{
using(var db = new LetLordContext())
{
predicate = predicate.And(x => x.HasBackGarden);
predicate = predicate.And(x => x.HasFrontGarden);
predicate = predicate.And(x => x.HasSecureParking);
predicate = predicate.And(x => x.IsDisabledFriendly);
var results = db.ResidentialProperty.AsExpandable().Where(
predicate).ToList();
return PartialView("_BasicPropertySearchResultsPartial", results);
}
}
ModelState.AddModelError("", "Something went wrong...");
return View("_BasicPropertySearchPartial");
}
How do I access results
in the view if the view the list is being passed to is not strongly typed?