1

我的项目(MVC3)N2CMS 2.2.1(来自nuget)中有以下内容。我可以使用“管理部件”功能编辑主页,并将图像部件拖到页面上并设置其内容。但是,当它呈现页面时,它会在 _layout.cshtml 内呈现我的 Image.cshtml 文件(就像它用于页面,而不是一部分一样)......这导致网站有多个页眉/页脚等标签并破坏布局。我怎样才能让 DroppableZones 正确呈现局部(无需在每个局部视图中手动设置 Layout = "")。如果您想自己测试,可以从https://github.com/robbihun/N2CMSBaseStarterSite查看代码运行它,使用 sqlite db 完成 N2CMS 设置并使用管理部件功能 (http://screencast.com/t/w9q5a49Ei8) 将图像部件拖到主页上。

_layout.cshtml

<body>
    @{ Html.ControlPanel().Render(); }
    @RenderBody()

    <footer>&copy; @DateTime.Now.Year</footer>
    @RenderSection("scripts", false)
</body>

开始主页.cshtml

<div>
@{ Html.DroppableZone(Zones.ImageSlider).Render(); }
</div>

图片.cshtml

@model ImagePart

    <div class="image">
    <img src="@Model.Image" alt="@Model.Title" />
        <span class="title">@Model.Title</span>
        <span class="description">@Model.ShortDescription</span>
    </div>

起始主页.cs

[PageDefinition("Start Page", Description = "The start or home page of the website.", SortOrder = 1, InstallerVisibility = InstallerHint.PreferredRootPage | InstallerHint.PreferredStartPage)]
[WithEditableTitle("Title", 1, Focus = true, ContainerName = Tabs.Content)]
[RestrictParents(typeof(IRootPage))]
public class StartHomePage : PageBase
{
    [EditableFreeTextArea("Main Content", 2, ContainerName = Tabs.Content)]
    public virtual string MainContent { get; set; }
}

图像部分.cs

[PartDefinition("Image Part", Description = "Image with title and description.")]
[WithEditableTitle("Title", 10)]
public class ImagePart : PartBase
{
    [FileAttachment, EditableImageUpload("Image", 5)]
    public virtual string Image { get; set; }

    [EditableTextBox("Short Description", 15, TextMode = TextBoxMode.MultiLine, Rows = 5, Columns = 15)]
    public virtual string ShortDescription { get; set; }
}
4

1 回答 1

0

在 Views/Shared/Parts 文件夹中添加 _ViewStart.cshtml,它将覆盖该文件夹中的布局设置。在新的 _ViewStart 中,设置Layout = null;和不设置局部视图中的布局。

这是一个拉取请求:https ://github.com/robbihun/N2CMSBaseStarterSite/pull/1

于 2012-01-17T19:27:56.723 回答