2013-12-18 54 views
1

傳遞這是我dropdownlistFor當dropdownlitFor被禁用,值始終爲0

@Html.DropDownListFor(m => m.objTicket.DepartmentId, new SelectList(Model.objTicket.Departments, "DepartmentId", "Department"), 
"-- Select Department--", new { id = "Deptment"}, disabled="disabled") 

如何傳遞已經被存儲在objTicket.DepartmentId價值?

如果我更改刪除disabled =「disabled」,我得到我的正確值。

回答

2

表單字段使用名稱而不是ID提交。瀏覽器不會提供禁用的控件值。放置一個@Html.HiddenFor字段,其​​名稱和ID不同,如下所示。

@Html.DropDownListFor(m => m.objTicket.DepartmentId, new SelectList(Model.objTicket.Departments, "DepartmentId", "Department"),Department--", new { id = "Deptment"}, disabled="disabled") 
@Html.HiddenFor(m => m.objTicket.DepartmentId, new { id="Deptment2" }) 
+0

謝謝!有效 ! :) – Joseph