So the way I have got this setup involves ClientController in the Controllers Folder. And in the Views Folder, I have SearchClient.cshtml and _SearchClients.cshtml. I am using Ajax and following the tutorial from this link : http://techfunda.com/howto/291/search-database-using-ajax
to get my search to work.
Here is how the methods in my controller look like :-
public ActionResult SearchClient()
{
return View();
}
public PartialViewResult _SearchClients(string searchString = "")
{
var clients = repository.Get(c => c.isDeleted == false);
clients = clients.Where(s =>
(s.FirstName.Contains(searchString)) ||
(s.MiddleName.Contains(searchString)) ||
(s.LastName.Contains(searchString))
).ToList();
return PartialView(clients);
}
And finally , here is the partial view :-
@model IEnumerable<Entities.Client>
@foreach (var item in Model)
{
<tr>
<td>@item.FirstName</td>
<td>@item.MiddleName</td>
<td>@item.LastName</td>
<td>@item.Phone</td>
<td>@item.Email</td>
<td>@item.AgencyID</td>
<td>@item.StreetAddress</td>
<td>@item.City</td>
<td>@item.PostalCode</td>
<td>@item.Province</td>
</tr>
}