它看起來像下拉列表視圖的當前實例(因此「旅遊&郵輪」是您搜索和包含在你的搜索結果後,查詢字符串的一部分)保持其價值,但不保留其下拉本身的價值。基本上,傳遞到將在下一頁時顯示的視圖的模型沒有選定的旅遊類型限制。您可以重新綁定控制器中的屬性。
然而,在一般情況下,我會建議使用剃刀助手做你的模型綁定,而不是一個明確的標籤,這可能避免在首位這一問題。
與單個下拉通用例子...
型號
public class YourModel {
public int SelectedTourismType { get; set; }
public IEnumerable<TourismType> TourismTypes { get; set; }
}
旅遊類類型:
public class TourismType {
public int TourismTypeID { get; set; }
public string DisplayName { get; set; }
// other properties if applicable
}
查看:
@model YourModel
// Your form or whatever here...
@Html.DropDownListFor(m => m.SelectedTourismType,
new SelectList(Model.TourismTypes, "TourismTypeID", "DisplayNameName"),
"Select an option") // Default text before the user has selected an option
控制器:
public ActionResult YourAction()
{
YourModel model = new YourModel();
model.TourismTypes= new List<TourismType> {
new TourismType { TourismTypeID = 1, Value = "Tours & Cruises" },
new TourismType { TourismTypeID = 2, Value = "Some other type name" }
}
return View("YourViewName", model);
}
只要您在刷新下一頁上的視圖時通過相同的模型,就應該可以工作。當然,你需要修改它以包含兩個下拉列表,一個取決於另一個。
你是對的,但爲什麼它同樣dropdown.can的所有其他選項的工作請您檢查此鏈接.. http://www.ourplanettravel.com.au/ – neha