我有一个带有两个下拉列表的视图,用于搜索描述。结果列表现在显示在另一个视图中。我希望在同一个搜索视图中生成结果。我假设一些AJAX
或Jquery
可以用来解决这个问题,但不知道如何。那么,在这种情况下,如何将搜索结果显示在同一个视图页面中呢?
此外,我对Search controller
. 我希望至少选择一个下拉列表(两个下拉列表都不应为空)。我怎样才能验证那部分?
看法
@using (Html.BeginForm("Search","Work",FormMethod.Get))
{
<fieldset>
<legend>Search</legend>
<div class="editor-label">
@Html.LabelFor(model => model.JobTypeID, "Job Type")
</div>
<div class="editor-field">
@Html.DropDownList("JobTypeID", "Select Job Type")
</div>
<div class="editor-label">
@Html.LabelFor(model => model.JobPriorityID, "Job Priority")
</div>
<div class="editor-field">
@Html.DropDownList("JobPriorityID", "Select Job Priority")
</div>
<p>
<input type="submit" value="Search" />
</p>
</fieldset>
}
控制器:
[HttpGet]
public ActionResult Search(int? jobtypeid, int? jobpriorityid)
{
var vJobDescriptions = new List<JobDescription>();
if (jobtypeid != null && jobpriorityid != null )
{
vJobDescriptions = (from description in db.JobDescriptions
where (description.JobTypeID == jobtypeid && description.JobPriorityID == jobpriorityid)
select description).ToList();
}
else if (jobtypeid == null && jobpriorityid != null)
{
vJobDescriptions = (from description in db.JobDescriptions
where (description.JobPriorityID == jobpriorityid)
select description).ToList();
}
else if (jobtypeid != null && jobpriorityid == null)
{
vJobDescriptions = (from description in db.JobDescriptions
where (description.JobTypeID == jobtypeid)
select description).ToList();
}
else
{
vJobDescriptions = (from description in db.JobDescriptions
select description).ToList();
}
return View(vJobDescriptions);
}