【发布时间】:2017-10-14 22:57:24
【问题描述】:
我正在开发网络应用程序项目,我正在尝试使用 ajax 进行搜索。
我使用 ajax.beginform() 创建了一个搜索表单,但遇到了一个小问题: 当我的文本框字段为空并且我单击搜索时,我希望视图返回所有实体(例如没有发生搜索),但它返回空视图。 如果字符串为空但没有成功,我尝试检查控制器。
1.文本字段为空时参数取什么值?
2.如何以这种形式发送几个参数?
提前谢谢你!
阿维夫p>
.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);
}
【问题讨论】:
-
"Country" 参数来自哪里...??
标签: c# jquery ajax asp.net-mvc asp.net-ajax