我有一个下拉列表和一个文本框,其中的下拉列表中的数据非常多。所以我想在文本框上创建过滤器功能,当我们在文本框中填写单词并按下过滤器按钮后,下拉菜单中出现的只有与文本框相对应的单词。 下面是我的代码
控制器
MM/DD/YYYY
查看
public ActionResult GetInsuranceCompany(string code)
{
string codeJP = string.Empty;
ParamJenisPembayaran paramJP = db.ParamJenisPembayarans.Where(x => x.Code == code).FirstOrDefault();
if (paramJP != null) codeJP = paramJP.Name;
var states = db.InsuranceCompany_CSFs.Where(x => x.JenisPembayaran == codeJP).ToList();
List<SelectListItem> listates = new List<SelectListItem>();
listates.Add(new SelectListItem { Text = "--Select InsuranceCompany--", Value = "0" });
if (states != null){
foreach (var x in states){
listates.Add(new SelectListItem { Text = x.CompanyName, Value = x.CompanyName});
}
}
return Json(new SelectList(listates, "Value", "Text", JsonRequestBehavior.AllowGet));
}
[HttpPost]
[MultipleButton(Name = "action", Argument = "SearchFilterThirdParty")]
public ActionResult SearchFilterThirdParty(ParamBlacklistPembayaranViewModel model)
{
//code
}
查看模型
@Html.EditorFor(model => model.SearchFilterThirdParty, new { htmlAttributes = new { @class = "form-control" } }) //textbox to filter the dropdown below
<input type="submit" value="Filter" name="action:SearchFilterThirdParty" />
@Html.DropDownListFor(model => model.AddNewThirdParty, ViewBag.country as List<SelectListItem>, new { @class = "form-control" })
public ActionResult GetInsuranceCompany 将根据先前选择的列表(级联DropDownList)调用另一个下拉列表中的所有数据,而我使用ajax使其工作了。我在上面的代码中未包含其他下拉菜单。 我知道公共操作结果SearchFilterThirdParty 仍然为空,我想为过滤器创建一个函数,但我不知道如何。任何想法?谢谢。