0

I'm trying to figure out how to disable an Html.Checkbox with the given syntax:

@Html.CheckBox("checkbox_" + Model.QuestionId.ToString(), false, 
               new Dictionary<string, object> {{ "data-bind", "checked: $root.getResponse(@Model.QuestionId).Value" }})

Knockout code:

self.getResponse = function (questionId) { 
      var rv = ko.utils.arrayFirst(self.responses(), function (item) { return item.QuestionId ==     questionId; }); 
      if (rv == null) {
          rv = new Response(0, questionId, self.evaluationId, 0, 0, '', '');  self.responses.push(rv); 
      } 
      return rv; 
 }

Please help

rwisch45
  • 3,692
  • 2
  • 25
  • 36
user3272686
  • 853
  • 2
  • 11
  • 23
  • Where does $root.getResponse come from? – jacqijvv Feb 10 '14 at 19:23
  • knockout: self.getResponse = function (questionId) { var rv = ko.utils.arrayFirst(self.responses(), function (item) { return item.QuestionId == questionId; }); if (rv == null) { rv = new Response(0, questionId, self.evaluationId, 0, 0, '', ''); self.responses.push(rv); } return rv; } – user3272686 Feb 10 '14 at 19:26

1 Answers1

1

data-bind='enable : isEnabled'

You want to test if this checkbox is supposed to be enabled. I don't know your criteria for being enabled, but here is the binding for enable/disable

Matthew
  • 411
  • 4
  • 14