title: Mixing Knockout and Razor Variables
body: <p>I am struggling with what I imagine is a really daft problem. I am iterating through a collection in Knockout.JS using 'foreach', and need to create a link for each item using variables within the collection.</p>
  
  <p>The problem is that my url is generated on the fly using variables from the view model, and I need to combine these with variables in the Knockout collection.</p>
  
  <p>Here is my block containing the Knockout loop.</p>
  
  <pre><code>    &lt;div data-bind="foreach: pagedList" class="span8" style="border-bottom: 1px solid #0094ff;"&gt;
          &lt;div style="cursor: pointer;"&gt;                 
  
              &lt;p data-bind="text: hotelId"&gt;&lt;/p&gt;
              &lt;p data-bind="text: name"&gt;&lt;/p&gt;
              &lt;p data-bind="text: hotelRating"&gt;&lt;/p&gt;
              &lt;p data-bind="text: propertyCategory"&gt;&lt;/p&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;   
  </code></pre>
  
  <p>Ideally I want to add the link to the parent div through the 'onclick="window.location=' method. I have tried using Action.Link and adding in the Knockout variables through string concatenation, as so;</p>
  
  <pre><code>&lt;div style="cursor: pointer;" onclick="window.location="@Url.Action( "Index", "Hotel",                new { regionId = Model.region.regionId, regionName =     HttpUtility.UrlPathEncode(Model.region.regionNameLong.ToString().Replace(",","")).Replace("%20","-"), hotelId = " + hotelID() + ", hotelName =   HttpUtility.UrlPathEncode(Convert.ToString(" + name() +     ").Replace(",","")).Replace("%20","-") })"&gt; &lt;/div&gt;
  </code></pre>
  
  <p>But this gives an 'Object not instantiated error'. Secondly, I tried using Knockout first, through the 'data-bind="attr:' method, as so;</p>
  
  <pre><code>&lt;a href="someurl" data-bind="attr: { href: '/Region/' + '@Model.region.regionId    ' + '/' + '@HttpUtility.UrlPathEncode(Model.region.regionNameLong.ToString().Replace(",","")).Replace("%20","-")    ' + '/' + hotelID() + '/' + '@HttpUtility.UrlPathEncode(Convert.ToString(" + name() + ").Replace(",","")).Replace("%20","-")' }, text: hotelId()"&gt;&lt;/a&gt;
  </code></pre>
  
  <p>Again no dice.</p>
  
  <p>I know this is mixing client side and server side paradigms, but can't think of another way without ditching Knockout. </p>
  
  <p>Does anybody have any experience with this? </p>