在 ASP MVC 淹没列表中使用默认值的情况下,我需要代码返回所有值或简单地忽略该特定搜索条件。
下面是我在视图和控制器中的代码。由于 '%' 似乎不起作用,是否还有另一个关键字/运算符可以完成这项工作?
看法:
<form method="post">
<select name="Table" title="Table" style="font-size:8pt;">
<option value="%">--Table Name--</option>
<option value="AgentContEd">CE</option>
<option value="AgentProductTraining">PT</option>
</select>
<select name="IssueType" style="font-size:8pt;">
<option value="%">--Issue Type--</option>
<option value="W">Warning</option>
<option value="E">Error</option>
</select>
<select name="Status" style="font-size:8pt;">
<option value="%">--Status Type--</option>
<option value="O">Open</option>
<option value="U">Under Review</option>
</select>
<input type="image" src="@Url.Content("~/Content/Images/Filter.bmp")" alt="Filter" style="padding-top: 0px;" />
<a href="#" style="padding-left: 30px;"></a>
</form>
控制器:
public ViewResult Index(FormCollection dropDownSelection)
{
//security
//if (!Security.IsViewer(User)) return RedirectToAction("Message", "Home", new { id = 2 });
//if (ViewBag.Level == 0) return RedirectToAction("Message", "Home", new { id = 2 });
string table = dropDownSelection["Table"];
string issue = dropDownSelection["IssueType"];
string status = dropDownSelection["Status"];
var followUpItem = from follow in db.FollowUpItems
where follow.TableName.Equals(table) &&
follow.IssueType.Equals(issue) &&
follow.Status.Equals(status)
select follow;
return View(followUpItem.ToList());
}