如何在博客/新闻项目页面上显示自定义小部件-Sitefinity

问题描述

我有一个页面,其中包含2个自定义小部件(页眉和页脚)和一个MVC新闻小部件,其中显示了所有博客文章的列表。

单个/单个新闻页面不会呈现我的自定义窗口小部件。

我遇到了建议重写HandleUnkNownAction的解决方案。我已经在自定义窗口小部件控制器中尝试了多种变体,但是它们没有起作用。在前端,将在其中渲染小部件,在前端收到错误消息:“执行控制器时发生异常。检查错误日志以了解详细信息。

此时,我假设控制器中可能存在一些错误,因此我附加了一个自定义小部件的全部内容

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Sitefinity.Mvc;
using EuroChange.DLL;
using EuroChange.BLL;
using SitefinityWebApp.Mvc.Models.BranchLocator;
using SitefinityWebApp.Filter;
using EuroChange.DLL.Data;
using Telerik.Sitefinity.Model.Localization;
using Telerik.Sitefinity.Publishing;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Search;
using Telerik.Sitefinity.Services.Search.Data;
using Telerik.Sitefinity.Services.Search.Model;
using Telerik.Sitefinity.Services.Search.Publishing;
using System.Globalization;
using Telerik.Sitefinity.Modules.News;
using SitefinityWebApp.Mvc.Models;
using System.Web.Script.Serialization;
using Telerik.Sitefinity.Frontend.Designers;
using Telerik.Sitefinity.Frontend.Lists.Mvc.Controllers;

namespace SitefinityWebApp.Mvc.Controllers
{
    [ControllerToolBoxItem(Name = "SPfooterPrimaryLinks",Title = "Footer Primary Links",SectionName = "SP Widgets")]
    public class SPfooterPrimaryLinksController : Controller
    {
        public string ListButtons { get; set; }
        public string ListButtonsTwo { get; set; }
        public string ListButtonsThree { get; set; }
        public string ListButtonsFour { get; set; }
        public string ListButtonsFive { get; set; }
        public string ListButtonsSix { get; set; }
        public string ListButtonsSeven { get; set; }
        public string ListButtonsEight { get; set; }


        public ActionResult Index()
        {

            this.ViewBag.ListButtons = this.DeserializeItems();
            this.ViewBag.ListButtonsTwo = this.DeserializeItemsTwo();
            this.ViewBag.ListButtonsThree = this.DeserializeItemsThree();
            this.ViewBag.ListButtonsFour = this.DeserializeItemsFour();
            this.ViewBag.ListButtonsFive = this.DeserializeItemsFive();
            this.ViewBag.ListButtonsSix = this.DeserializeItemsSix();
            this.ViewBag.ListButtonsSeven = this.DeserializeItemsSeven();
            this.ViewBag.ListButtonsEight = this.DeserializeItemsEight();

            return this.View();

        }

        protected override void HandleUnkNownAction(string actionName)
       {
        //    this.ActionInvoker.InvokeAction(this.ControllerContext,"Index");
            //Index().ExecuteResult(ControllerContext);
           //View("Index").ExecuteResult(this.ControllerContext);
            this.Index().ExecuteResult(this.ControllerContext);
        }

        private IList<SPfooterPrimaryLinksModel> DeserializeItems()
        {
            var serializer = new JavaScriptSerializer();
            IList<SPfooterPrimaryLinksModel> buttons = new List<SPfooterPrimaryLinksModel>();

            if (!string.IsNullOrEmpty(this.ListButtons))
                buttons = serializer.Deserialize<IList<SPfooterPrimaryLinksModel>>(this.ListButtons);

            return buttons;
        }

        private IList<SPfooterPrimaryLinksTwoModel> DeserializeItemsTwo()
        {
            var serializer = new JavaScriptSerializer();
            IList<SPfooterPrimaryLinksTwoModel> buttonsTwo = new List<SPfooterPrimaryLinksTwoModel>();

            if (!string.IsNullOrEmpty(this.ListButtonsTwo))
                buttonsTwo = serializer.Deserialize<IList<SPfooterPrimaryLinksTwoModel>>(this.ListButtonsTwo);

            return buttonsTwo;
        }

        private IList<SPfooterPrimaryLinksThreeModel> DeserializeItemsThree()
        {
            var serializer = new JavaScriptSerializer();
            IList<SPfooterPrimaryLinksThreeModel> buttonsThree = new List<SPfooterPrimaryLinksThreeModel>();

            if (!string.IsNullOrEmpty(this.ListButtonsThree))
                buttonsThree = serializer.Deserialize<IList<SPfooterPrimaryLinksThreeModel>>(this.ListButtonsThree);

            return buttonsThree;
        }

        private IList<SPfooterPrimaryLinksFourModel> DeserializeItemsFour()
        {
            var serializer = new JavaScriptSerializer();
            IList<SPfooterPrimaryLinksFourModel> buttonsFour = new List<SPfooterPrimaryLinksFourModel>();

            if (!string.IsNullOrEmpty(this.ListButtonsFour))
                buttonsFour = serializer.Deserialize<IList<SPfooterPrimaryLinksFourModel>>(this.ListButtonsFour);

            return buttonsFour;
        }

        private IList<SPfooterPrimaryLinksFiveModel> DeserializeItemsFive()
        {
            var serializer = new JavaScriptSerializer();
            IList<SPfooterPrimaryLinksFiveModel> buttonsFive = new List<SPfooterPrimaryLinksFiveModel>();

            if (!string.IsNullOrEmpty(this.ListButtonsFive))
                buttonsFive = serializer.Deserialize<IList<SPfooterPrimaryLinksFiveModel>>(this.ListButtonsFive);

            return buttonsFive;
        }

        private IList<SPfooterPrimaryLinksSixModel> DeserializeItemsSix()
        {
            var serializer = new JavaScriptSerializer();
            IList<SPfooterPrimaryLinksSixModel> buttonsSix = new List<SPfooterPrimaryLinksSixModel>();

            if (!string.IsNullOrEmpty(this.ListButtonsSix))
                buttonsSix = serializer.Deserialize<IList<SPfooterPrimaryLinksSixModel>>(this.ListButtonsSix);

            return buttonsSix;
        }

        private IList<SPfooterPrimaryLinksSevenModel> DeserializeItemsSeven()
        {
            var serializer = new JavaScriptSerializer();
            IList<SPfooterPrimaryLinksSevenModel> buttonsSeven = new List<SPfooterPrimaryLinksSevenModel>();

            if (!string.IsNullOrEmpty(this.ListButtonsSeven))
                buttonsSeven = serializer.Deserialize<IList<SPfooterPrimaryLinksSevenModel>>(this.ListButtonsSeven);

            return buttonsSeven;
        }
        private IList<SPfooterPrimaryLinksEightModel> DeserializeItemsEight()
        {
            var serializer = new JavaScriptSerializer();
            IList<SPfooterPrimaryLinksEightModel> buttonsEight = new List<SPfooterPrimaryLinksEightModel>();

            if (!string.IsNullOrEmpty(this.ListButtonsEight))
                buttonsEight = serializer.Deserialize<IList<SPfooterPrimaryLinksEightModel>>(this.ListButtonsEight);

            return buttonsEight;
        }

    }
}

更新 这些是来自违规页面错误日志:

08/17/2020 22:46:39
Type : System.Reflection.TargetInvocationException,mscorlib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089
Message : Exception has been thrown by the target of an invocation.
Source : mscorlib
Help link : 
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Object InvokeMethod(System.Object,System.Object[],System.Signature,Boolean)
HResult : -2146232828
Stack Trace :    at System.RuntimeMethodHandle.InvokeMethod(Object target,Object[] arguments,Signature sig,Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object[] parameters,Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,CultureInfo culture)
   at Telerik.Sitefinity.Mvc.ControllerWrapper.CallHandleUnkNownAction(String actionName)
   at Telerik.Sitefinity.Mvc.ControllerWrapper.Execute()
   at Telerik.Sitefinity.Mvc.ControllerActionInvoker.ExecuteController(MvcProxyBase proxyControl)
   at Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Routing.FeatherActionInvoker.ExecuteController(MvcProxyBase proxyControl)

Additional Info:

MachineName : DESKTOP-057IG4E
TimeStamp : 08/17/2020 21:46:39
FullName : Telerik.Sitefinity.Utilities,Version=9.2.6211.0,PublicKeyToken=b28c218413bdf563
AppDomainName : /LM/W3SVC/3/ROOT-1-132421743230335362
ThreadIdentity : 
WindowsIdentity : IIS APPPOOL\NM-Money
Requested URL : https://localhost:44651/news/2018/05/06/ready-steady-go!
    Inner Exception
    ---------------
    Type : system.invalidOperationException,PublicKeyToken=b77a5c561934e089
    Message : The view '2018' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/SPfooterPrimaryLinks/2018.cshtml
~/Views/Shared/2018.cshtml
~/Frontend-Assembly/SitefinityWebApp/Mvc/Views/SPfooterPrimaryLinks/2018.cshtml
~/Frontend-Assembly/SitefinityWebApp/Mvc/Views/Shared/2018.cshtml
~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/SPfooterPrimaryLinks/2018.cshtml
~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/Shared/2018.cshtml
~/Views/SPfooterPrimaryLinks/2018.aspx
~/Views/SPfooterPrimaryLinks/2018.ascx
~/Views/Shared/2018.aspx
~/Views/Shared/2018.ascx
~/Frontend-Assembly/SitefinityWebApp/Mvc/Views/SPfooterPrimaryLinks/2018.aspx
~/Frontend-Assembly/SitefinityWebApp/Mvc/Views/SPfooterPrimaryLinks/2018.ascx
~/Frontend-Assembly/SitefinityWebApp/Mvc/Views/Shared/2018.aspx
~/Frontend-Assembly/SitefinityWebApp/Mvc/Views/Shared/2018.ascx
~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/SPfooterPrimaryLinks/2018.aspx
~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/SPfooterPrimaryLinks/2018.ascx
~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/Shared/2018.aspx
~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/Shared/2018.ascx
~/Views/SPfooterPrimaryLinks/2018.vbhtml
~/Views/Shared/2018.vbhtml
~/Frontend-Assembly/SitefinityWebApp/Mvc/Views/SPfooterPrimaryLinks/2018.vbhtml
~/Frontend-Assembly/SitefinityWebApp/Mvc/Views/Shared/2018.vbhtml
~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/SPfooterPrimaryLinks/2018.vbhtml
~/Frontend-Assembly/Telerik.Sitefinity.Frontend/Mvc/Views/Shared/2018.vbhtml
    Source : System.Web.Mvc
    Help link : 
    Data : System.Collections.ListDictionaryInternal
    TargetSite : System.Web.Mvc.ViewEngineResult FindView(System.Web.Mvc.ControllerContext)
    HResult : -2146233079
    Stack Trace :    at System.Web.Mvc.ViewResult.FindView(ControllerContext context)
       at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
       at SitefinityWebApp.Mvc.Controllers.SPfooterPrimaryLinksController.HandleUnkNownAction(String actionName) in C:\dev\Sites\NM-Money\EChange\Mvc\Controllers\SPfooterPrimaryLinks\SPfooterPrimaryLinksController.cs:line 62



Category: ErrorLog

Priority: 0

EventId: 9010

Severity: Warning

Title:Enterprise Library Exception Handling

Machine: DESKTOP-057IG4E

App Domain: /LM/W3SVC/3/ROOT-1-132421743230335362

ProcessId: 3256

Process Name: c:\windows\system32\inetsrv\w3wp.exe

Thread Name: 

Win32 ThreadId:10092

Extended Properties: 

解决方法

感谢维斯林(Veselin)解决了这个问题。

在索引方法中指定视图可解决此问题

不起作用:

public ActionResult Index()
{
  return this.View();
}

工作:

public ActionResult Index()
{
  return View("Index");
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...