0
過濾的搜索這是我目前在我Index.cs
:我如何與多個字段
@model IEnumerable<MvcApplication7.Models.vwtest21>
<p>
@using (Html.BeginForm("Index", "Home", FormMethod.Get))
{
<b>Search By:</b> @Html.RadioButton("searchBy", "PROGCD", true) <text>PROGCD</text>
@Html.RadioButton("searchBy", "Date") <text>DOCRECDT</text><br />
@Html.TextBox("search") <input type="submit" value="Search" />
}
</p>
我想它從一個RadioButton
轉換爲兩個場過濾的搜索爲PROGCD
和DOCRECDT
一個提交按鈕。以下是我的HomeController
,如果將其更改爲過濾搜索,我不知道如何轉換。
public class HomeController : Controller
{
private ProjectDBContext db = new ProjectDBContext();
public ActionResult Index(string searchBy, string search)
{
if (searchBy == "Date") //searchBy == "PROGCD")
{
return View(db.vwtest21.Where(x => x.DOC_REC_DT1 == search).ToList());
}
else
{
return View(db.vwtest21.Where(x => x.PROG_CD == search).ToList());
}
}
謝謝,這正是我正在尋找的! – ayton