我正在處理web應用程序項目,我試圖包括使用ajax搜索。ASP.NET MVC 5 - ajax.beginform()與空參數
我使用ajax.beginform()創建了一個搜索表單,並且我有一個小問題: 當我的文本框爲空,並且單擊搜索時,我希望視圖返回所有實體(例如不發生搜索) ,但它返回空視圖。 我試圖檢查控制器,如果字符串爲空,但沒有成功。
1.當文本字段爲空時參數獲得什麼值?
2.如何發送幾個參數?
預先感謝您!
特拉維夫
.cshtml - 查看
@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 - 控制器
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);
}
哪裏是從哪裏來的「國家」參數... ?? –