在Orchard 1.7中的Visual Studio中创建自定义小部件

时间:2013-08-08 04:25:51

标签: orchardcms

我正在尝试使用两个输入字段名称和电子邮件地址构建一个非常简单的小部件。现在我正在关注http://www.deepcode.co.uk/search?q=how+to+build+a+widget+without+a+model+in+Orchard

Migration.cs

public int UpdateFrom22()
{
    ContentDefinitionManager.AlterTypeDefinition("QuickLinkWidget", builder => builder
    .WithPart("QuickLinkWidgetPart")
    .WithPart("CommonPart")
    .WithPart("WidgetPart")
    .WithSetting("Stereotype", "Widget"));

    return 23;
}

ContentPartRecord(Models / QuickLinkWidgetRecord.cs)

public class QuickLinkWidgetRecord : ContentPartRecord

{
    //We shall not define any property for this class.
    //We shall not create any HANDLER for this widget because we do not need to store any data to our database.
}

ContentPart :( Models / QuickLinkWidgetPart.cs)

public class QuickLinkWidgetPart : ContentPart<QuickLinkWidgetRecord>
{
    //Again we shall not definte any Record property here......
    //We shall not create any HANDLER for this widget because we do not need to store any data to our database.
}

处理程序

未定义任何内容,因为我没有处理任何存储库。

驱动程序:((Models / QuickLinkWidgetDriver.cs))

public class QuickLinkWidgetDriver : ContentPartDriver<QuickLinkWidgetPart>

{
    override DriverResult Display(QuickLinkWidgetPart part, string displayType, dynamic shapeHelper)
    {
    //We do not have any property defined in Model class.
    //So we don't have to assign any Default values to anything!
    //We shall just return a SHAPE of the widget
    }
}

Placement.info:

<Place Widgets_QuickLinkWidget="AsideFirst:1" />

最后是View:Views / Widgets / QuickLinkWidget.cshtml

@using Emfluence.Intrust.Models;

@model Contact

<h2>Our Side link widget</h2>

我在视图中添加了额外的内容

请帮助我理解我做错了什么。为什么我根本无法看到渲染的小部件?我在最近3天坚持使用它!只是想先看它渲染!

提前感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我有类似的问题,我通过更改我的placement.info文件中的一些设置来实现它......在你的情况下试试这个

<Place Widgets_QuickLinkWidget="Content" />