title: Using knockout binding with razor syntax
body: <p>I am wondering if it is possible to use a <strong>Knockout</strong> <code>data-bind</code> within <strong>Razor</strong> syntax.</p>
  
  <p>I have this code in my view:</p>
  
  <pre><code>&lt;tbody data-bind="foreach: relays"&gt;
      &lt;tr&gt;
          &lt;td id="body-button-column"&gt;
              &lt;button class="btn btn-default btn-sm" title="Remove relay" data-bind="click: $parent.removeRelay"&gt;
                  &lt;i class="glyphicon glyphicon-remove-circle"&gt;&lt;/i&gt;
              &lt;/button&gt;
          &lt;/td&gt;
          &lt;td&gt;&lt;input type="text" data-bind="value: $index"/&gt;&lt;/td&gt;
          &lt;td&gt;@Html.DropDownList("RelayConfigurations[" + $index + "].Address", Model.Addresses, "Select an Item")&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>And my viewmodel has the following property</p>
  
  <pre><code>self.relays = ko.observableArray(@Html.Raw(Json.Encode(Model.RelayConfigurations)));
  </code></pre>
  
  <p>where the RelayConfigurations is a collection object on the model.</p>
  
  <p>In the line using the Razor syntax <code>@Html.DropDownList</code>.... I would like to use a knockout binding for the $index value but am not sure how to do that.  Or if it is even possible.</p>
  
  <p>If I replace the <code>$index</code> in that line with a hard-coded value of zero, the model binding in the controller action works as expected on <strong>Postback</strong> (albeit only the first relay in the collection has any data because of the hard-coded value of zero).</p>