Do you want to choose a non-selective choice?
<%= Html.ListBoxFor( m => m.Choices,
Model.ChoicesMenu,
new { disabled = "disabled" } ) %>
The idea is that your model should have IEnumerable<SelectListItem>one that will contain possible key / value pairs for your selection, here ChoicesMenu. The actual values selected, if they can be selected, will be published in the property Choices. Use a signature that allows you to specify html attributes and disable it so you don’t select it. You can of course do this (or undo) using javascript.
Model:
public class ViewModel
{
public int[] Choices { get; set; }
public IEnumerable<SelectListItem> ChoicesMenu { get; set; }
}
Action (corresponding bit)
var model = new ViewModel
{
ChoicesMenu = db.Items
.Select( i => new SelectListItem
{
Text = i.Name,
Value = i.ID.ToString()
} );
}
source
share