2013-10-11 101 views
0

你好我是一個MVC項目我在哪裏停留在下拉菜單選擇的非常小的問題的工作。下拉選擇問題MVC

有用於國名和第2個1個2 dropdown.1st用於旅遊類型。

而且一個鍵根據下拉選擇用於搜索。

下面是該網站的鏈接:

www.ourplanettravel.com.au/

如果我們從第一個下拉列表中選擇「塔斯馬尼亞」,並從下拉第二屆「旅遊&郵輪」並點擊搜索按鈕然後,第二個下拉失去其只有在這種情況下值(它顯示了選擇,或旅遊類型 - ),而在其他選項時,它完美的作品。

這裏是我使用的代碼:

 <select id='TourismType' name="TourismType"> 
     <option value=''>--Choose Tourism Type--</option> 
     {{if $item.data.oTourismType}} 
     {{each $item.data.oTourismType}} 

    <option value='${Text}'>${Text}</option> 
    {{/each}} 

    </select> 
    {{/if}} 

請建議我在哪裏,我錯了。

回答

0

它看起來像下拉列表視圖的當前實例(因此「旅遊&郵輪」是您搜索和包含在你的搜索結果後,查詢字符串的一部分)保持其價值,但不保留其下拉本身的價值。基本上,傳遞到將在下一頁時顯示的視圖的模型沒有選定的旅遊類型限制。您可以重新綁定控制器中的屬性。

然而,在一般情況下,我會建議使用剃刀助手做你的模型綁定,而不是一個明確的標籤,這可能避免在首位這一問題。

與單個下拉通用例子...

型號

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); 
} 

只要您在刷新下一頁上的視圖時通過相同的模型,就應該可以工作。當然,你需要修改它以包含兩個下拉列表,一個取決於另一個。

+0

你是對的,但爲什麼它同樣dropdown.can的所有其他選項的工作請您檢查此鏈接.. http://www.ourplanettravel.com.au/ – neha