“Html.DroppableZone(“h1”).Render()”上的 N2 NullReferenceException

发布于 2024-10-27 19:32:06 字数 1189 浏览 6 评论 0原文

我目前正在评估 N2 CMS 用于多个网站。

我们只想向客户提供“拖动”功能,这意味着他们可以将部件添加到页面上的区域,填写它们,然后拖动它们。管理区的“后端”功能将保留给开发人员。

因此,我不使用SlidingCurtain控件来渲染。现在,我已经制作了一个自定义管理面板,当具有正确角色的用户登录时会显示该面板。通常,当您单击“拖动”功能时,滑动窗帘会向您的 URL 添加“?edit=drag”查询字符串按钮,因此我在登录后自动添加此查询字符串。

如果这样做,我会在以下行中收到 NullReferenceException: Html.DroppableZone("H1").Render();

截至目前,该 DroppableZone 上还没有任何部件,我想这就是导致此问题的原因。我该如何解决这个问题?

我有以下 H1Controller:

namespace EmptyCMS.Controllers
{
    [Controls(typeof(Models.H1))]
    public class H1Controller : ContentController<Models.H1>
    {
        public override ActionResult Index()
        {
            return PartialView("H1", CurrentItem);
        }
    }
}

和以下部分视图:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Models.H1>" %>

 <h1><%= Model.Text %></h1>

这是我的模型:

namespace EmptyCMS.Models
{
    [PartDefinition("H1")]
    [AllowedZones("H1")]
    public class H1 : ContentItem
    {
        [EditableTextBox("Text", 100)]
        public virtual string Text { get; set; }
    }
}

谁能发现我做错了什么?非常感谢您能给我的任何帮助。

I'm currently evaluating N2 CMS for use for multiple websites.

We would only like to offer the 'drag' functionality to our clients, which means they can add parts to Zones on the page, fill them out, and drag them around. The "backend" functionality of the management zone will be reserved for the developers.

Therefore, I don't use the SlidingCurtain control to render. Right now, I've made a custom Admin Panel that appears when a user with the correct role is logged in. Normally, the Sliding Curtain adds a "?edit=drag" query string to your URL when you click the 'drag' functionality button, so I add this querystring automatically after logging in.

If I do this, I get a NullReferenceException to the following line:
Html.DroppableZone("H1").Render();

As of this moment, there are no parts on this DroppableZone yet, and I suppose this is what is causing this problem. How do I get around this?

I have the following H1Controller:

namespace EmptyCMS.Controllers
{
    [Controls(typeof(Models.H1))]
    public class H1Controller : ContentController<Models.H1>
    {
        public override ActionResult Index()
        {
            return PartialView("H1", CurrentItem);
        }
    }
}

And the following partialview:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Models.H1>" %>

 <h1><%= Model.Text %></h1>

And this is my model:

namespace EmptyCMS.Models
{
    [PartDefinition("H1")]
    [AllowedZones("H1")]
    public class H1 : ContentItem
    {
        [EditableTextBox("Text", 100)]
        public virtual string Text { get; set; }
    }
}

Can anyone spot what I'm doing wrong? Thanks a lot for any help you can give me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光礼记 2024-11-03 19:32:06

只检查是否为空?

var zone = Html.DroppableZone("H1");
if(zone != null)
    zone.Render();

Just check for null?

var zone = Html.DroppableZone("H1");
if(zone != null)
    zone.Render();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文