0

I need some help for proper binding the model to a list of checkboxes (Mon-Sun).

Any help is appreciated. Thanks.

enter image description here

SERVER Model

public class DailySchedule : ReportSchedule
{
    public string Option { get; set; }
    public Dictionary<string, bool> RunOnDays { get; set; }
}

JSON Data I receive from server comes in this format:

vm.reportSchedule
{
  "Option": "EveryWeekday",
  "RunOnDays": {
    "Mon": true,
    "Tue": true,
    "Wed": true,
    "Thu": true,
    "Fri": true,
    "Sat": false,
    "Sun": false
  }
}

HTML

<div class="form-group">
    <input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Mon">Mon
    <input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Tue">Tue
    <input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Wed">Wed
    <input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Thu">Thu
    <input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Fri">Fri
    <input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Sat">Sat
    <input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Sun">Sun
</div>

1 Answer 1

2

Use an ngRepeat with the key/val syntax:

<div class="form-group">
    <input ng-repeat="(day, bool) in vm.reportSchedule.RunOnDays" type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays[day]" />{{day}}
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.