1
我正在使用Asp.Net MVC4。我在查看頁面中有一個html選擇。我想在回發後保持選定的值。如何在回發後維護dropdownlist選定值?
查看:
@using (Html.BeginForm("TaxMaster", "Masters", FormMethod.Get))
{
<div>
<select id="ddlSearchBy" name="ddlSearchBy" style="width: 150px">
<option value="TaxCode">Tax Code</option>
<option value="TaxDescription">Tax Description</option>
<option value="ClassDescription">Class Description</option>
<option value="ZoneName">Zone Name</option>
</select>
<input type="text" class="input-small" name="txtSearchValue" id="txtSearchValue" placeholder="Enter Search Value" style="width: 225px" /> 
<button type="button" id="btnSearch" class="btn btn-small btn-primary">Search</button>
</div>
}
MastersController.cs:
[HttpGet]
public ActionResult TaxMaster(string txtSearchValue, string ddlSearchBy)
{
TaxMaster objTaxTable = new TaxMaster();
objTaxTable.TaxTable = new List<moreInsights_offinvoice_taxmaster>();
objTaxTable.TaxTable = GetTaxMasterTable(ddlSearchBy, txtSearchValue);
return View(objTaxTable);
}
在這裏,過濾器,我有一個下拉菜單,文本框和按鈕。當我選擇下拉菜單並單擊搜索按鈕時,選定的值將傳遞給控制器類,並將過濾的數據返回給視圖。但下拉不能保持選定的值。它再次重置。如何在MVC中保持下拉選定值?
它可以幫助你:http://stackoverflow.com/questions/6981698/how-to-keep-dropdownlist-selected-value-after-postback –
只是回答[這個類似的問題](http://stackoverflow.com/questions/33488883/asp-net-mvc-filter-view-with-selected-combo/33510236#33510236) –