我有兩個下拉列表和兩個文本框如何從搜索文本框清晰的文本搜索完成後在MVC
Search By: ByHtml.DropDownList("Search1", "Please Select...")
Html.TextBox("searchString1")
Search By: Html.DropDownList("Search2", "Please Select...")
@Html.TextBox("searchString2")
<input type="submit" value="Filter" />
當我把我從哪個DDL和類型文本到文本框中選擇,打我過濾後搜索返回,但是在搜索之後文本保留在文本框中,是否有一種方法可以在搜索之後清除它,以便文本框再次爲空?我試過
ModelState.Remove("");
但它沒有工作。
從我的控制器代碼的樣品是
public class MainController : Controller
{
private DBEntities db = new DBEntities();
// GET: /Main/
public ActionResult Index(string searchString1, string searchString2, string Search1, string Search2)
{
//Create a Dropdown list
var SearchOptionList = new List<string>();
SearchOptionList.Add("LandLord");
SearchOptionList.Add("Postcode");
SearchOptionList.Add("Street Address");
ViewBag.Search1 = new SelectList(SearchOptionList);
ViewBag.Search2 = new SelectList(SearchOptionList);
var mylist = from m in "mydatabase" select m;
//This statement runs if the user selects a parameter from Search2 and leaves Search1 empty
if (String.IsNullOrEmpty(Search1) && !String.IsNullOrEmpty(Search2))
{
if (Search2 == "Postcode")
{
mylist = mylist.Where(s => s.Postcode.Contains(searchString2));
}
if (Search2 == "LandLord")
{
mylist = mylist.Where(s => s.Name.Contains(searchString2));
}
if (Search2 == "Street Address")
{
mylist = mylist.Where(s => s.StreetAddress.Contains(searchString2));
}
}
return View(mylist.ToList());
}
你可以做你控制器,分享你的控制器代碼以及回答 – 2014-12-02 16:24:08
我已經用我的控制器中的一些示例代碼更新了我的問題 – Scanner 2014-12-02 16:27:39
你的模特班是什麼?通常情況下,您應該清除模型類中傳回您的視圖的對象中的值。 – Floremin 2014-12-02 16:46:31