>Hi everybody,
>
>I am trying to write a Search method that can accept two parameters (no or Name). Here is what I've started, but I don't know how should I declare "clients" variable at the top correctly. What is it when used in LINQ query?
>
>
>public ActionResult Search(int? clientNo = null, string clientName = null)
> {
>
> if (((clientNo??0) == 0) && (String.IsNullOrEmpty(clientName)==true))
> {
> // Assume we want to select everything
> var clients = Db.Clients.OrderBy(c => c.Name);
> }
> var clients = Db.Clients.Where(c => (c.Number == clientNo)).OrderBy(c => c.Name);
>
> return PartialView("_ClientsSearch", clients);
> }
>
>Since I can not declare var clients twice, what will be correct solution here?
>
>Thanks in advance.
Having read the entire thread, I can't believe it. If you couldn't figure this out on your own, maybe you should look for another line of work. This is elementary coding.
Also, var is used to infer the type of a given variable. It cannot stand alone as a definition in that it can't imply the type. You have to assign something to it that can be typed, i.e. var clients = db.clients.... var clients = myClients.GetType() or whatever. In addition, the statement ''String.IsNullOrEmpty(ClientName)" doesn't need the '== true' after it. Boolean values stand on their own as either true of false....