NullReferenceException,在Umbraco 4.9中改编了Create

时间:2012-12-17 11:19:28

标签: c# umbraco nullreferenceexception

我已经调整了Umbraco创建上下文菜单项以复制内容。我一直在努力解决小问题,但我现在卡住了。在尝试使用dialogHandler_temp.Create()方法时,我收到NullReferenceException

使用的所有变量都不为空,也不是页面。有没有人知道如何对此进行排序?

    private void DoCreation()
{
    if (!Page.IsValid)
        return;

    var hel = helper.Request("nodeType");
    var nType = int.Parse(nodeType.SelectedValue);
    var nId = int.Parse(Request["nodeID"]);
    var rName = rename.Text;
    var cur = Current;


    if (cur != null) // dialogHandler_temp.Create() is a static method
        cur.ClientTools.ChangeContentFrameUrl(dialogHandler_temp.Create(hel, nType, nId, rName)).CloseModalWindow();
} 

堆栈追踪:

 [NullReferenceException: Object reference not set to an instance of an object.]
   umbraco.presentation.create.dialogHandler_temp.Create(String NodeType, Int32 TypeId, Int32 NodeId, String Text) +278
   OptionalMultiLangPage.DoCreation() in c:\inetpub\wwwAmaris\optional_multiLang.aspx.cs:112
   OptionalMultiLangPage.SbmtClick(Object sender, EventArgs e) in c:\inetpub\wwwAmaris\optional_multiLang.aspx.cs:96
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3803

1 个答案:

答案 0 :(得分:0)

我对此进行了排序。我花了一段时间才意识到helper.Request("nodeType")不是要返回新节点的类型,而是返回正在完成的xml节点值。这必须在Umbraco Content类的某个地方分配,所以我错过了它。应将其设置为"content"的值。

我的代码现在看起来像:

 private void DoCreation()
    {
        if (!Page.IsValid)
            return;

        const string xmlNodeVal = "content";
        var nType = int.Parse(nodeType.SelectedValue);
        var nId = int.Parse(Request["nodeID"]);
        var rName = rename.Text;
        var returnUrl = dialogHandler_temp.Create(xmlNodeVal, nType, nId, rName);
        var cur = Current;

        if (cur != null)
            cur.ClientTools.ChangeContentFrameUrl(returnUrl).CloseModalWindow();
    }