1

In Company model, I have:

[Display(Name = "Offered Services")]
public string[] Services { get; set; }

and I have a standard scaffold controller.

Now, in Razor view I need to use the checkbox helper which auto binds the values to model such that the following markup is generated for browser:

<div class="editor-label">
    Offered Services
</div>
<div class="editor-field">

    <input type="checkbox" name="Services[]" id="services-safety" value="safety"  />
    <label for="services-safety">Safety</label>

    <input type="checkbox" name="Services[]" id="services-healthy" value="healthy"  />
    <label for="services-healty">Healthy</label>

    ... <!-- more checkboxes in future -->
</div>

Questions:

  • Is there any helper which binds it to model so the selected values are stay checked in edit view. Would it be possible without using extra ViewModel and controller code?

  • Is it a good idea to let the presenter change the behavior of application? If someone change the checkbox value from client-side, then Service array will contain garbage data. In this case what is the best approach to deal with checkboxes to prevent it from such noise:

    1. ViewModel for polymorphic service names
    2. Enum Service {}
    3. Create separate properties for each service in Company model
    4. class Service{}: containing all services as properties:

      A) then make a property of the type Services in the model.

      B) Make Service as a entity and make association with Company.

tereško
  • 58,060
  • 25
  • 98
  • 150
Annie
  • 3,090
  • 9
  • 36
  • 74
  • This question is very broad as it stands. You need to narrow it down to a specific problem or you will not get useful answers. If you have multiple questions, ask them separately. – Ant P Sep 08 '13 at 10:36
  • possible duplicate of [CheckboxList in MVC3 View and get the checked items passed to the controller](http://stackoverflow.com/questions/5284395/checkboxlist-in-mvc3-view-and-get-the-checked-items-passed-to-the-controller) – Imad Alazani Sep 08 '13 at 10:37

0 Answers0