Skip to content Skip to sidebar Skip to footer

Razor DropDownList For Each And All Elements

Is there a way to create DropDownList with Razor and pass second parameter as Linq result instead of default empty item? The key is that I'm using accumulator function ('Function')

Solution 1:

Filter method uses delegates that need parameter to construct Linq query.

The problem was that DDL was passing null as result for selecting "All" items in DDL. Because of that Linq was getting a null so expressions like n => n.Name == null obviously didn't work.

To deal with null parameters I used CodeMaster's hint from linked question :

return View(unitofwork.DomainRepository.Filter(n => n.Name.Contains(searchFullName), n => (String.IsNullOrEmpty(searchExtension) || n.Extension == searchExtension), n => (String.IsNullOrEmpty(searchProject) || n.Project == searchProject)));

Post a Comment for "Razor DropDownList For Each And All Elements"