我有以下ListBoxFor在HTML頁面,我幾乎嘗試了一切,使之只讀,但仍然沒有運氣:如何在c#MVC中使ListBoxFor只讀?
@Html.ListBoxFor(m => m.SelectedLocations, Model.GetLocationsNotInBuildingList(Model.idCompany, null), (edit ? extraData : new Dictionary<string, object> { { "disabled", "" } }))
我也曾嘗試以下解決方案,並沒有他們的工作:
@Html.ListBoxFor(m => m.SelectedLocations, Model.GetLocationsNotInBuildingList(Model.idCompany, null), new { @readonly = "readonly" })
@Html.ListBoxFor(m => m.SelectedLocations, Model.GetLocationsNotInBuildingList(Model.idCompany, null), (edit ? extraData : new Dictionary<string, object> { { "readonly", "readonly" } }))
@Html.ListBoxFor(m => m.SelectedLocations, Model.GetLocationsNotInBuildingList(Model.idCompany, null), (edit ? extraData : new Dictionary<string, object> { { "disabled", "disabled" } }))
任何建議都會有所幫助。
謝謝。
listbox本身只讀,你試着禁用它,對吧?怎麼看這個? https://forums.asp.net/t/1840939.aspx?How+to+make+ListBox+Read+only – Se0ng11
'edit'屬於什麼?我認爲'new {@readonly =「readonly」}'或'new {@disabled =「disabled」}'就足夠了(NB:'disable'屬性阻止提交列表框的值)。 –