2009-08-07 28 views
2

在我的asp.net mvc的觀點,我有一個選擇下拉菜單:下拉組合沒有出現在的FormCollection在控制器

<select id="userRole" name="userRole" disabled="true"> 

當我的表單提交到控制器,我有以下代碼:

[Authorize] 
    [AcceptVerbs(HttpVerbs.Post)] 
    public ActionResult Edit(FormCollection formCollection_) 
    { 
     string role = formCollection_["userRole"].ToString(); 
} 

但是當我看着formCollection對象時,沒有「userRole」的鍵。任何想法,爲什麼會這樣?

回答

2

應該只是

<select id="userRole" name="userRole" disabled> 

但禁用輸入will not be part of your FormCollectionsuccessful control

+0

這是一個有點奇怪。無論如何有一個控制禁用,但仍然傳遞給控制器​​。如果可能,我想避免任何klugy隱藏字段 – leora 2009-08-07 17:28:16

+0

嘗試只讀而不是禁用http://www.w3.org/TR/html401/interact/forms.html#h-17.12.2 – 2009-08-07 17:51:39

+0

是<... disabled>有效的標記?我認爲它必須被禁用=「禁用」? – 2009-08-08 07:32:15

相關問題