0

我已经调整了 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
4

1 回答 1

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();
    } 
于 2012-12-17T16:42:17.517 回答