我有一个淘汰赛JS视图模型,并希望使用外部的模板,得到一个MVC 4剃刀(CSHTML)绑定页面,以便初始页面可以在服务器上创建或通过淘汰赛的约束,我外部模板将在运行时决定。我想的模板的名称传递给这样的(/模板/ KnockoutTemplate?TEMPLATENAME =“规”)其中“规”是一个视图(radial.tmpl.cshtml)的名称的控制器和具有敲除把它在模板块。淘汰赛JS从MVC控制器
我的控制器:
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);
}
}
radial.cshtml
@model MVC4.Models.TemplatesViewModel
@{
ViewBag.Title = "Radial Template";
}
<div id="radialDashboardWidget" class="dashboardWidget" style="width: 100%">
<h4 class="bold">@Model.Heading </h4>
<!-- or I can do this, I'll decide at development time -->
<h4 class="bold" data-bind="text:heading"></h4>
</div>
主页
<div id="dashboardWidgets" data-bind="foreach: Widgets" class="flexible-widget">
<!-- ko template: {name: Properties.templateName } -->
<!-- /ko -->
<div class="clear" />
</div>
感谢页面,我编辑它使它成为现实尝试使之更加清晰。我希望能够利用这两种方法,并仍然加载模板与外部模板库KO。我有一个前进的方向,我只需要避开博客,而且我会在这里添加链接。 – Aligned 2012-08-24 18:43:27