我正在看MVC的N2 CMS最小范例(从这里开始 )
我已经想出了大部分内容,但是我看到N2支持可以放入“区域”的“零件”。
我如何获得区域和零件在最小范例中的工作?
Html.Zone()命令似乎并不适用于开箱即用。
I'm looking at the N2 CMS Minimal Example for MVC (from here)
I've figured out most of it, but I see that N2 supports 'Parts' that you can drop into 'Zones'.
How do I get Zones and Parts working in the minimal example?
The Html.Zone() command doesn't seem to work out-of-the-box.
最满意答案
在N2论坛上有来自libardo的一些帮助
以下是将区域和零件添加到MVC的N2最小示例的“最小”方式:
1)将此名称空间添加到web.config pages.namespaces节点中:
<pages> <namespaces> ... <add namespace="N2.Web.Mvc.Html"/> ...2)使用AvailableZones属性添加一个Container页面模型:
using N2.Integrity; ... [Definition("ContainerPage")] [AvailableZone("Right", "MyRightZone")] public class ContainerPage : N2.ContentItem { ...3)以通常的N2方式添加容器控制器,这里没有什么特别需要使它成为一个容器:
[Controls(typeof(ContainerPage))] public class ContainerController : ContentController<ContainerPage> { ...4)在容器的视图中,使用Html.DroppableZone函数:
<div class="n2zone"> <% Html.DroppableZone("MyRightZone").Render(); %> </div>5)添加一个零件模型,例如这个只显示标题为一个字符串。 请注意,PartDefinition是使其成为可以放入区域的部件的原因:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using N2; using N2.Details; namespace MyProject.Models { [PartDefinition("SimplePart")] [WithEditableTitle("Title", 10)] public class SimplePart : ContentItem { [DisplayableLiteral()] public override string Title { get { return base.Title; } set { base.Title = value; } } } }6)为零件添加一个控制器。 这是通常的N2控制器,除了我们重写索引以返回PartialView:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using N2.Web; using N2.Web.Mvc; using MyProject.Models; namespace MyProject.Controllers { [Controls(typeof(SimplePart))] public class SimplePartController : ContentController<SimplePart> { public override ActionResult Index() { return PartialView(CurrentItem); } } }7)最后,为零件控制器添加一个局部视图。 这里不需要特别的东西:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyProject.Models.SimplePart>" %> <div class="simplePart"> <%= Html.DisplayContent(m => m.Title) %> </div>在N2编辑器中,您可以随意将很多SimpleParts放入ContainerPage页面。
With a bit of help from libardo at the N2 forum
Here's the 'minimal' way of adding Zones and Parts to the N2 Minimal Example for MVC:
1) Add this namespace in the web.config pages.namespaces node:
<pages> <namespaces> ... <add namespace="N2.Web.Mvc.Html"/> ...2) Add a Container page model, using the AvailableZones attribute:
using N2.Integrity; ... [Definition("ContainerPage")] [AvailableZone("Right", "MyRightZone")] public class ContainerPage : N2.ContentItem { ...3) Add Container controller in the usual N2 manner, nothing special needed here to make it a container:
[Controls(typeof(ContainerPage))] public class ContainerController : ContentController<ContainerPage> { ...4) In the view for the container, use the Html.DroppableZone function:
<div class="n2zone"> <% Html.DroppableZone("MyRightZone").Render(); %> </div>5) Add a part model, e.g. this one just shows Title as a string. Note that PartDefinition is what makes it a Part that can be dropped into a Zone:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using N2; using N2.Details; namespace MyProject.Models { [PartDefinition("SimplePart")] [WithEditableTitle("Title", 10)] public class SimplePart : ContentItem { [DisplayableLiteral()] public override string Title { get { return base.Title; } set { base.Title = value; } } } }6) Add a Controller for the Part. This is the usual N2 controller except that we override Index to return a PartialView:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using N2.Web; using N2.Web.Mvc; using MyProject.Models; namespace MyProject.Controllers { [Controls(typeof(SimplePart))] public class SimplePartController : ContentController<SimplePart> { public override ActionResult Index() { return PartialView(CurrentItem); } } }7) Finally, add a partial view for the Part controller. Nothing special is needed here:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyProject.Models.SimplePart>" %> <div class="simplePart"> <%= Html.DisplayContent(m => m.Title) %> </div>In the N2 editor you can then drop as many SimpleParts as you like into the ContainerPage pages.
更多推荐
发布评论