I can pass the name of the template to the controller like this (/Templates/KnockoutTemplate?templateName='radial') where 'radial' is the name of a view (radial.cshtml), return a partial view of that name and have Knockout put it in the template block.
My Controller:
public class TemplatesController : Controller
{
public TemplatesViewModel viewModel { get; set; }
public ActionResult KnockoutTemplate(string templateName, int? id)
{
this.viewModel.Id = id;
return PartialView(templateName.Replace("/", string.Empty), this.viewModel);
}
}
radial.cshtml
@model MVC4.Models.TemplatesViewModel
@{
ViewBag.Title = "Radial Template";
}
<div id="radialDashboardWidget" class="dashboardWidget" style="width: 100%">
<h4 class="bold" data-bind="text:@Model.Heading">
</h4>
<!-- add more HTML -->
</div>
Dashboard page with Knockout
<div id="dashboardWidgets" data-bind="foreach: Widgets" class="flexible-widget">
<!-- ko template: {name: Properties.templateName } -->
<!-- /ko -->
<div class="clear" />
</div>
The route is:
routes.MapRoute(
name: "KnockoutTemplates",
url: "{controller}/{action}/{templateName}",
defaults: new { contoller = "Templates", action = "KnockoutTemplate" });
infuse
infuser.defaults.templateUrl = "/Templates/KnockoutTemplate?templateName=";
infuser.defaults.templateSuffix = "";
infuser.defaults.ajax.async = true;
Then if you want to add in the optional id, just append it to Properties.templateName before binding (properties.TemplateName + “&id=” + id).
I've asked this at StackOverflow, but didn't get an concrete responses.