<form id="frmClientsSearch"> <label for="clientNo">Client No: </label> <input type="number" name="searchClientNo" class="numericOnly" /><br /> <label for="clientName">Client Name: </label> <input type = "text" size =25 value ="Please enter the search value" name ="searchClientName" /> <input type="button" id="btnClientsSearch" value ="Find / Refresh" /> </form>and in the Client controller method I now have this code
public ActionResult Client(FormCollection formValues, int? searchClientNo = null, string searchClientName = "Please enter the search value") { // Assume we want to select everything var clients = Db.Clients; // Should set type of clients to IQueryable<Clients> if (searchClientNo == null && searchClientName == null) clients = clients.Where(c => (c.Number == searchClientNo)); else { if ((searchClientNo ?? 0) != 0) //Number was supplied clients = clients.Where(c => (c.Number == searchClientNo)); // 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(searchClientName)) // Part of the name was supplied clients = clients.Where(c => (c.Name.Contains(searchClientName))); }and so initially the view comes with that text and nothing in the grid and once I put values in the seach controls, they start to work.