I was trying to perform a search operation. Somehow I've managed to implement the search operation for a column. Now I want to Search through multiple columns. for an example if my table contains the name, number, email, gender. and if I search for word M and my name column contains a field as Mandy and if my email column contains as [email protected] I want them both to be displayed.
How would I do this?
view
<td>@Html.TextBoxFor(model => model.name, new { @placeholder = "search by name" })</td>
<td><input type="submit" value="search" class="btn-success" /></td>
MVC controller:
[HttpPost]
public ActionResult Index(Customer cvm)
{
CustomerClient cc = new CustomerClient();
ViewBag.listCustomers = cc.search(cvm.name);
return View();
}
client Class:
public IEnumerable<Customer> search(int name)
{
try
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(Base_URL);
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
var result = client.GetAsync(string.Format("customers/search/{0}", name)).Result;
if (result.IsSuccessStatusCode)
return result.Content.ReadAsAsync<IEnumerable<Customer>>().Result;
return null;
}
catch
{
return null;
}
}
API Controller:
[HttpGet]
[Route("search/{name}")]
public HttpResponseMessage search(int name)
{
try
{
var httpresponsemessage = new HttpResponseMessage();
httpresponsemessage.Content = new StringContent(
JsonConvert.SerializeObject(db.customers.Where(
p => p.name.Contains(name)).ToList()));
httpresponsemessage.Content.Headers.ContentType = new
MediaTypeHeaderValue("application/json");
return httpresponsemessage;
}
catch
{
return null;
}
}
ORcondition where you have managed to implement the search operation fornamecolumn?