I'm working on web application project and I'm trying to include search using ajax.
I created a search form using ajax.beginform() and I have a little problem: When my textbox field is empty and I click on search I want the view to return all the entities(like no search is occurred) , but it returns empty view. I tried to check in the controller if the string is null but no success.
1.what value the parameter gets when the text field is empty?
2.how do I send couple of parameters in this form?
Thank you in advance!
Aviv
.cshtml - View
@using (Ajax.BeginForm("BranchSearch", "Branches",
new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "searchResults" }))
{
<h3>Search:</h3>
<p>Branch name :</p>@Html.TextBox("Search", null, new { id = branchname"})
<input type="submit" value="Search" class="btn btn-primary" />
}
.cs - Controller
public PartialViewResult BranchSearch(String branchname, String country)
{
List<Branches> model = (from p in db.Branches
select p).ToList();
if(branchname!=null)
{
model = model.Where(x => x.BranchName.Equals(branchname)).ToList();
}
return PartialView("BranchSearch",model);
}