我有以下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'属性阻止提交列表框的值)。 –