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

如何解决如何在博客/新闻项目页面上显示自定义小部件-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");
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res