2014-04-24 73 views
0

我想要寫的查詢字符串,如果條件= 2查詢字符串下拉菜單MVC asp.net選擇的項目列表

我有下拉菜單在此菜單我有位置,它是{主,左,上,下} 如果我在LOCL主機本地主機中寫道:27593管理項目創建類型= 2 應該在的位置正好我看到左,在asp.net和MVC主要 我想寫代碼的權利plz幫助我

public ActionResult Create (int? id) 
    { 
     //querystring 
     // 2 ise 

     int TYPEE = HttpUtility.UrlDecode(Request.QueryString["typee"]); 
      string[] separateURL = url.Split('?'); 
     NameValueCollection queryString = 
        System.Web.HttpUtility.ParseQueryString(separateURL[1]) ; 
     if (TYPEE == 2) 
     { 
      SelectListItem[] items = new SelectListItem[2]; 
      items[0] = new SelectListItem"main" ,"1"); 
      items[1] = new SelectListItem("left" , "2"); 
      DropDownList1.Items.AddRange(items); 
      DropDownList1.DataBind(); 
     } 
     else 
     { 
      SelectListItem[] items = new SelectListItem[5]; 
      items[0] = new SelectListItem("main", "1"); 
      items[1] = new SelectListItem("left", "2"); 
      items[2] = new SelectListItem("right", "3"); 
      items[3] = new SelectListItem("top", "4"); 
      items[3] = new SelectListItem("bottom", "5"); 

      DropDownList1.Items.AddRange(items); 

      DropDownList1.DataBind(); 
      return View(); 

回答

0

你爲什麼不使用?

public ActionResult Create (int type, int? id) 

這樣的默認模型粘結劑將類型的值從查詢字符串變量類型進行綁定。

編輯:

我剛看到一個錯字也,你正在尋找的QueryString集合在「鍵入e」鍵,然而在它裏面沒有這樣的關鍵,只有「類型」關鍵是在它。

int TYPEE = HttpUtility.UrlDecode(Request.QueryString["type"])