title: Knockout js external template from a MVC Controller
body: <p>I have a Knockout js viewModel and want to use external templates to get an MVC 4 razor (cshtml) bound page so the initial page can be created on the server or bound through Knockout, I'll decide at runtime. I want to pass the name of the template to the controller like this (/Templates/KnockoutTemplate?templateName='gauge') where 'gauge' is the name of a view (radial.tmpl.cshtml) and have Knockout put it in the template block.</p>
  
  <p>My Controller:</p>
  
  <pre><code>public class TemplatesController : Controller
  {
       public TemplatesViewModel viewModel { get; set; }
       public TemplatesController()
       {
          this.viewModel = new TemplatesViewModel { Heading = "Radial" };
       }
  
      public ActionResult KnockoutTemplate(string templateName)
      {
          // is this right?
          return  PartialView(templateName, this.viewModel);
      }
  }
  </code></pre>
  
  <p>radial.cshtml</p>
  
  <pre><code>   @model MVC4.Models.TemplatesViewModel
      @{
          ViewBag.Title = "Radial Template";
      }
      &lt;div id="radialDashboardWidget" class="dashboardWidget" style="width: 100%"&gt;
       &lt;h4 class="bold"&gt;@Model.Heading &lt;/h4&gt;
       &lt;!-- or I can do this, I'll decide at development time  --&gt;
       &lt;h4 class="bold" data-bind="text:heading"&gt;&lt;/h4&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>main page</p>
  
  <pre><code>&lt;div id="dashboardWidgets" data-bind="foreach: Widgets" class="flexible-widget"&gt;
   &lt;!-- ko template: {name: Properties.templateName  } --&gt;
   &lt;!-- /ko --&gt;
   &lt;div class="clear" /&gt;
  &lt;/div&gt;
  </code></pre>