Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to declare the variable correctly?
Message
 
 
To
28/09/2012 17:13:48
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01553872
Message ID:
01553904
Views:
49
>You could also do this to allow both filters to work:
>
public ActionResult Search(int? clientNo = null, string clientName = null)
>        {
>            // Assume we want to select everything
>            var clients = Db.Clients; // Should set type of clients to IQueryable<Clients>
>            
>            if ((clientNo??0) != 0) //Number was supplied
>              clients = clients.Where(c => (c.Number == clientNo));
> 
>           // If clientNo was supplied, clients is now filtered by that. If not, it still has the full list. The following will further filter it.
>            if (!String.IsNullOrWhitespace(clientName) ) // Part of the name was supplied
>                clients = clients.Where(c => (c.Name.Contains(clientName)));
>
>           // Order the filtered list
>              clients = clients.OrderBy(c => c.Name);
>
>            return PartialView("_ClientsSearch", clients);
>        }
Rob,

What is IsNullOrWhitespace - is it your own method?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform