c# - MVC 2 - Passing enum to CheckBoxFor -
let's assume have model:
public class document {     public string name { get; set;}     public list<dayofweek> weekdays { get; set; } }   is possible render checkboxes represent days of week model? i've searched internet did not find solution.
i mean works whith checkboxfor(model=> model.someproperty) not work if someproperty list<dayofweek>. dayofweek here enumeration.  
thanks in advance.
you can enumerate on values of enum , manually create checkboxes.  using same name each checkbox submit them array in actionmethod.
<% foreach(var value in enum.getvalues(typeof(dayofweek))) { %>      <% var name = enum.getname(typeof(dayofweek), value); %>      <label for="dayofweek<%=value %>"><%=name %></label>      <input type="checkbox" id="dayofweek<%=value %>" name="dayofweek" value="<%=value %>" /> <% } %>   your action method like:
public actionresult save(dayofweek[] dayofweek) {      // stuff }      
Comments
Post a Comment