asp.net-mvc – N2 for MVC – 如何让Zones工作?
发布时间:2020-12-16 09:14:48 所属栏目:asp.Net 来源:网络整理
导读:我正在看MVC的 N2 CMS最小示例(从 here开始) 我已经弄明白了大部分内容,但我看到N2支持’部分’,你可以放入’区域’. 如何在最小的示例中使用区域和部件? Html.Zone()命令似乎没有开箱即用的功能. 解决方法 从 libardo at the N2 forum获得一点帮助 这是将
我正在看MVC的
N2 CMS最小示例(从
here开始)
我已经弄明白了大部分内容,但我看到N2支持’部分’,你可以放入’区域’. 如何在最小的示例中使用区域和部件? Html.Zone()命令似乎没有开箱即用的功能. 解决方法
从
libardo at the N2 forum获得一点帮助
这是将区域和部件添加到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方式添加Container控制器,这里没有什么特别需要使它成为一个容器: [Controls(typeof(ContainerPage))] public class ContainerController : ContentController<ContainerPage> { ... 4)在容器的视图中,使用Html.DroppableZone函数: <div class="n2zone"> <% Html.DroppableZone("MyRightZone").Render(); %> </div> 5)添加零件模型,例如这个只是将Title显示为一个字符串.请注意,PartDefinition是使其成为可以放入区域的Part的原因: 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)最后,为Part控制器添加局部视图.这里没有什么特别之处: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MyProject.Models.SimplePart>" %> <div class="simplePart"> <%= Html.DisplayContent(m => m.Title) %> </div> 在N2编辑器中,您可以将任意数量的SimplePart拖放到ContainerPage页面中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 为MVC3应用程序中的某些操作启用并要求SSL
- asp.net-core-mvc – 如何在Asp.Net Core MVC 1.0(又名MVC
- ASP.NET(C#)Web服务中的异常处理
- asp.net-mvc – ASP.NET MVC:Uri到可用的路由数据
- Asp.net核心IIS 8.5:找不到视图“索引”
- asp.net-mvc-4 – 如何在一个Web应用程序中最好地组合Web A
- asp.net-mvc – 在App_Code中的共享@helper中使用@Html
- asp.net-mvc – Controller Action方法仅在第一次获得.它为
- .net – 为每个用户创建子域
- asp.net-mvc – ASP.NET MVC 2中的验证是如何实际工作的?
推荐文章
站长推荐
- asp.net – 控制FormsAuthentication createPers
- asp.net – 从网页打印条形码标签
- 如何为ASP.NET MVC Web应用程序中使用的图像添加
- asp.net-mvc-3 – 如何将现有文件夹与其所有子文
- asp.net – MVC3:如何强制Html.TextBoxFor使用模
- asp.net-mvc – 如何在ASP.NET MVC的所有操作中安
- 如何使用MVC5 ASP.NET Identity Framework对Sign
- 在更新到ASP.NET 4后,IE中的会话“立即过期”?
- .net – 如何将多个数据视图合并为一个?
- asp.net-web-api2 – SwashBuckle / Swagger –
热点阅读