C# 如何解决DNN自定义模块不渲染的问题?

C# 如何解决DNN自定义模块不渲染的问题?,c#,dotnetnuke,C#,Dotnetnuke,我正在使用DNN9.3.2和Chris Hammond的模块模板来创建自定义模块。当我将模块加载到没有可见性限制的页面上时,它不会呈现。安装或呈现所述页面后,事件日志不包含任何错误 由于这是我的第一个DNN MVC模块,我认为这与我创建的以下控制器类有关: [DnnHandleError] public class SignupController : DnnController { // GET: Signup [ModuleAction(Control

我正在使用DNN9.3.2和Chris Hammond的模块模板来创建自定义模块。当我将模块加载到没有可见性限制的页面上时,它不会呈现。安装或呈现所述页面后,事件日志不包含任何错误

由于这是我的第一个DNN MVC模块,我认为这与我创建的以下控制器类有关:

    [DnnHandleError]
    public class SignupController : DnnController
    {
    // GET: Signup
    [ModuleAction(ControlKey = "Edit", TitleKey = "AddItem")]
    public ActionResult Index()
    {
        var signups = OnboardingManager.Instance.GetOnboardings(ModuleContext.ModuleId);
        return View(signups);
    }

    [HttpPost]
    [DotNetNuke.Web.Mvc.Framework.ActionFilters.ValidateAntiForgeryToken]
    public ActionResult Edit(Models.Onboarding onboarding)
    {
        ProPayService service = new ProPayService();

            OnboardingManager.Instance.CreateOnboarding(onboarding);
            service.MerchantSignupForProPayAsync();

            return RedirectToDefaultRoute();
    }

    public ActionResult Edit(int onboardingId = -1)
    {

     DotNetNuke.Framework.JavaScriptLibraries.JavaScript.RequestRegistration(CommonJs.DnnPlugins);

        var userlist = UserController.GetUsers(PortalSettings.PortalId);
        var users = from user in userlist.Cast<UserInfo>().ToList()
            select new SelectListItem { Text = user.DisplayName, Value = user.UserID.ToString() };

        ViewBag.Users = users;

        var onboarding = (onboardingId == -1) ? new Models.Onboarding{ModuleId = ModuleContext.ModuleId} : OnboardingManager.Instance.GetOnboarding(onboardingId, ModuleContext.ModuleId);
        return View(onboarding);

    }
}
我修改后的DNN清单如下所示:

<dotnetnuke type="Package" version="5.0">
<packages>
<package name="Onboarding" type="Module" version="00.00.01">
  <friendlyName>Onboarding</friendlyName>
  <description>Onboarding</description>
  <iconFile>~/Icons/Sigma/Software_32X32_Standard.png</iconFile>
  <owner>
    <name>SocialBodega.com</name>
    <organization>SocialBodega.com</organization>
    <url>https://www.socialbodega.com/</url>
    <email>info@socialbodega.com</email>
  </owner>
  <license src="License.txt"></license>
  <releaseNotes src="ReleaseNotes.txt"></releaseNotes>
  <dependencies>
    <dependency type="CoreVersion">08.00.00</dependency>
  </dependencies>
  <components>
    <component type="Script">
      <scripts>
        <basePath>DesktopModules\MVC\Onboarding</basePath>
        <script type="Install">
          <path>Providers\DataProviders\SqlDataProvider</path>
          <name>00.00.01.SqlDataProvider</name>
          <version>00.00.01</version>
        </script>
        <script type="UnInstall">
          <path>Providers\DataProviders\SqlDataProvider</path>
          <name>Uninstall.SqlDataProvider</name>
          <version>00.00.01</version>
        </script>
      </scripts>
    </component>
    <component type="ResourceFile">
      <resourceFiles>
        <basePath>DesktopModules/MVC/Onboarding</basePath>
        <resourceFile>
          <name>Resources.zip</name>
        </resourceFile>
      </resourceFiles>
    </component>
    <component type="Module">
      <desktopModule>
        <moduleName>Onboarding</moduleName>
        <foldername>Onboarding</foldername>
     <businessControllerClass>SocialBodega.Onboarding.
     Components.FeatureController, 
     SocialBodega.Onboarding</businessControllerClass>
        <supportedFeatures />
        <moduleDefinitions>
          <moduleDefinition>
            <friendlyName>Onboarding</friendlyName>
            <defaultCacheTime>0</defaultCacheTime>
            <moduleControls>
              <!--<moduleControl>
                <controlKey />
             <controlSrc>SocialBodega.Onboarding.Controllers/Item/Index.mvc
             </controlSrc>
                <supportsPartialRendering>False</supportsPartialRendering>
                <controlTitle />
                <controlType>View</controlType>
                <iconFile />
                <helpUrl />
                <viewOrder>0</viewOrder>
              </moduleControl>-->
              <moduleControl>
                <controlKey/>

          <controlSrc>SocialBodega.Onboarding.Controllers/Signup/Index.mvc
          </controlSrc>
                <supportPartialRendering>False</supportPartialRendering>
                <controlTitle/>
                <controlType>View</controlType>
                <iconFile/>
                <helpUrl/>
                <viewOrder>0</viewOrder>
                <supportsPopUps>True</supportsPopUps>
              </moduleControl>
              <moduleControl>
                <controlKey>Edit</controlKey>


           <controlSrc>SocialBodega.Onboarding.Controllers/Signup/Edit.mvc
           </controlSrc>
                <supportsPartialRendering>False</supportsPartialRendering>
                <controlTitle>Edit Signups</controlTitle>
                <controlType>Edit</controlType>
                <iconFile />
                <helpUrl />
                <viewOrder>0</viewOrder>
                <supportsPopUps>True</supportsPopUps>
              </moduleControl>
              <moduleControl>
                <controlKey>Settings</controlKey>

       <controlSrc>SocialBodega.Onboarding.Controllers/Settings/Settings.mvc
       </controlSrc>
                <supportsPartialRendering>False</supportsPartialRendering>
                <controlTitle>Onboarding Settings</controlTitle>
                <controlType>Edit</controlType>
                <iconFile />
                <helpUrl />
                <viewOrder>0</viewOrder>
              </moduleControl>
            </moduleControls>
          </moduleDefinition>
        </moduleDefinitions>
      </desktopModule>
    </component>
    <component type="Assembly">
      <assemblies>
        <assembly>
          <name>Onboarding.dll</name>
          <path>bin</path>
        </assembly>
      </assemblies>
    </component>
  </components>
</package>

入职
入职
~/Icons/Sigma/Software\u 32X32\u Standard.png
SocialBodega.com
SocialBodega.com
https://www.socialbodega.com/
info@socialbodega.com
08.00.00
DesktopModules\MVC\Onboard
提供程序\DataProviders\SqlDataProvider
00.00.01.SqlDataProvider
00.00.01
提供者\数据提供者\ SqlDataProvider
卸载.SqlDataProvider
00.00.01
DesktopModules/MVC/Onboard
Resources.zip
入职
入职
社会博迪加。入职。
组件。特性控制器,
社会博迪加酒店
入职
0
SocialBodega.Onboarding.Controllers/Signup/Index.mvc
假的
看法
0
真的
编辑
SocialBodega.Onboarding.Controllers/Signup/Edit.mvc
假的
编辑注册
编辑
0
真的
设置
SocialBodega.Onboarding.Controllers/Settings/Settings.mvc
假的
入职设置
编辑
0
}
}

}

}
@*@标签(“测试123”)*@
当我构建解决方案时,它成功了,但我在Visual Studio 2019中确实收到了16条错误消息,大意是:

Error   CS0012  The type 'WebViewPage<>' is defined in an assembly that is 
not referenced. You must add a reference to assembly 'System.Web.Mvc, 
Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.  
1_desktopmodules_mvc_onboarding_Views_Signup_Index.cshtml    
C:\websites\dnndev.me\DesktopModules\Onboarding\Views\Signup\Index.cshtml   
错误CS0012类型“WebViewPage”是在以下程序集中定义的:
未引用。必须添加对程序集“System.Web.Mvc”的引用,
版本=5.1.0.0,区域性=中性,PublicKeyToken=31bf3856ad364e35'。
1_desktopmodules_mvc_Onboard_Views_Signup_Index.cshtml
C:\websites\dnndev.me\DesktopModules\onboard\Views\Signup\Index.cshtml
我已使用以下方法将上述程序集添加到模块视图文件夹中的web.config,以及C:\webs.dnndev.me中的主DNN web.config:

    <compilation debug="true" targetFramework="4.7.2">
  <assemblies>
    <add assembly="System.Web.Mvc, Version = 5.1.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35"/>
    <add assembly ="netstandard, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = cc7b13ffcd2ddd51"/>
  </assemblies>
</compilation>


如何防止抛出错误并确保我的视图按需要呈现?

首先,确保您的模块是根据DNN实例所针对的.NET Framework的正确版本编译的。您可以在web.config文件中查找一行,类似于以下内容:


在DNN的最新版本中,您需要确保明确地告诉DNN您的控制器要响应的权限。注意下面示例中的
DnnModuleAuthorize
类装饰

使用系统;
使用System.Web.Mvc;
使用DotNetNuke.Entities.Modules;
使用DotNetNuke.Security;
使用DotNetNuke.Services.Exceptions;
使用DotNetNuke.Web.Mvc.Framework.ActionFilters;
命名空间SocialBodega.Onboarding.Controllers
{   
[DNNModuleAuthorization(AccessLevel=SecurityAccessLevel.View)]
[DnnHandleError]
公共类注册控制器:DnnBaseController
{  
//获得:注册
[ModuleAction(ControlKey=“Edit”,TitleKey=“AddItem”)]
公共行动结果索引()
{  
var signups=OnboardingManager.Instance.GetOnboardings(ModuleContext.ModuleId);
返回视图(注册);
}  
}  
}  

我会使用像wireshark或fiddler这样的嗅探器,看看你的状态是否为200 OK。您可能会遇到错误。返回空响应,或未得到响应。若你们有一个应用程序可以工作,那个么将工作代码中的第一个请求和非工作代码进行比较。然后让你的c#看起来像是工作代码。所以当我浏览安装了结节的页面时,Fiddler给出了HTTP 200。然后HttpPost和请求很好,问题是解析响应。发布的代码是针对请求而不是响应的。您也可以发布您的dnn清单吗?我已经在更新的问题中添加了我的服务类逻辑和dnn清单的内容。谢谢你的帮助。
<dotnetnuke type="Package" version="5.0">
<packages>
<package name="Onboarding" type="Module" version="00.00.01">
  <friendlyName>Onboarding</friendlyName>
  <description>Onboarding</description>
  <iconFile>~/Icons/Sigma/Software_32X32_Standard.png</iconFile>
  <owner>
    <name>SocialBodega.com</name>
    <organization>SocialBodega.com</organization>
    <url>https://www.socialbodega.com/</url>
    <email>info@socialbodega.com</email>
  </owner>
  <license src="License.txt"></license>
  <releaseNotes src="ReleaseNotes.txt"></releaseNotes>
  <dependencies>
    <dependency type="CoreVersion">08.00.00</dependency>
  </dependencies>
  <components>
    <component type="Script">
      <scripts>
        <basePath>DesktopModules\MVC\Onboarding</basePath>
        <script type="Install">
          <path>Providers\DataProviders\SqlDataProvider</path>
          <name>00.00.01.SqlDataProvider</name>
          <version>00.00.01</version>
        </script>
        <script type="UnInstall">
          <path>Providers\DataProviders\SqlDataProvider</path>
          <name>Uninstall.SqlDataProvider</name>
          <version>00.00.01</version>
        </script>
      </scripts>
    </component>
    <component type="ResourceFile">
      <resourceFiles>
        <basePath>DesktopModules/MVC/Onboarding</basePath>
        <resourceFile>
          <name>Resources.zip</name>
        </resourceFile>
      </resourceFiles>
    </component>
    <component type="Module">
      <desktopModule>
        <moduleName>Onboarding</moduleName>
        <foldername>Onboarding</foldername>
     <businessControllerClass>SocialBodega.Onboarding.
     Components.FeatureController, 
     SocialBodega.Onboarding</businessControllerClass>
        <supportedFeatures />
        <moduleDefinitions>
          <moduleDefinition>
            <friendlyName>Onboarding</friendlyName>
            <defaultCacheTime>0</defaultCacheTime>
            <moduleControls>
              <!--<moduleControl>
                <controlKey />
             <controlSrc>SocialBodega.Onboarding.Controllers/Item/Index.mvc
             </controlSrc>
                <supportsPartialRendering>False</supportsPartialRendering>
                <controlTitle />
                <controlType>View</controlType>
                <iconFile />
                <helpUrl />
                <viewOrder>0</viewOrder>
              </moduleControl>-->
              <moduleControl>
                <controlKey/>

          <controlSrc>SocialBodega.Onboarding.Controllers/Signup/Index.mvc
          </controlSrc>
                <supportPartialRendering>False</supportPartialRendering>
                <controlTitle/>
                <controlType>View</controlType>
                <iconFile/>
                <helpUrl/>
                <viewOrder>0</viewOrder>
                <supportsPopUps>True</supportsPopUps>
              </moduleControl>
              <moduleControl>
                <controlKey>Edit</controlKey>


           <controlSrc>SocialBodega.Onboarding.Controllers/Signup/Edit.mvc
           </controlSrc>
                <supportsPartialRendering>False</supportsPartialRendering>
                <controlTitle>Edit Signups</controlTitle>
                <controlType>Edit</controlType>
                <iconFile />
                <helpUrl />
                <viewOrder>0</viewOrder>
                <supportsPopUps>True</supportsPopUps>
              </moduleControl>
              <moduleControl>
                <controlKey>Settings</controlKey>

       <controlSrc>SocialBodega.Onboarding.Controllers/Settings/Settings.mvc
       </controlSrc>
                <supportsPartialRendering>False</supportsPartialRendering>
                <controlTitle>Onboarding Settings</controlTitle>
                <controlType>Edit</controlType>
                <iconFile />
                <helpUrl />
                <viewOrder>0</viewOrder>
              </moduleControl>
            </moduleControls>
          </moduleDefinition>
        </moduleDefinitions>
      </desktopModule>
    </component>
    <component type="Assembly">
      <assemblies>
        <assembly>
          <name>Onboarding.dll</name>
          <path>bin</path>
        </assembly>
      </assemblies>
    </component>
  </components>
</package>
@inherits 
DotNetNuke.Web.Mvc.Framework.DnnWebViewPage
<DotNetNuke.Collections.PagedList<SocialBodega.Onboarding.
Models.Onboarding>>

@using System.Linq
@using System.Text.RegularExpressions
@using DotNetNuke.Collections
@using DotNetNuke.Entities.Urls
@using DotNetNuke.Web.Mvc.Helpers

<div id="Onboarding-@Dnn.ModuleContext.ModuleId">
@if (Model == null|| !Model.Any())

    {
    <p>@Dnn.LocalizeString("NoSignups")</p>
}
else
{
    <ul>
        @foreach (var onboarding in Model)
        {
            <li>
                <h3>@onboarding.FirstName</h3>
                <div>@onboarding.OnboardingId</div>
                @{
                    if (Dnn.ModuleContext.IsEditable)
                    {
                        <div>
                            <a href="@Url.Action("Edit","Signup", new{ctl = "Edit", onboardingId = onboarding.OnboardingId, })">@Dnn.LocalizeString("EditItem")</a>
                        </div>
                    }
                }
            </li>
        }
    </ul>
}
</div>
@*@Html.Label("Testing 123");*@
Error   CS0012  The type 'WebViewPage<>' is defined in an assembly that is 
not referenced. You must add a reference to assembly 'System.Web.Mvc, 
Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.  
1_desktopmodules_mvc_onboarding_Views_Signup_Index.cshtml    
C:\websites\dnndev.me\DesktopModules\Onboarding\Views\Signup\Index.cshtml   
    <compilation debug="true" targetFramework="4.7.2">
  <assemblies>
    <add assembly="System.Web.Mvc, Version = 5.1.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35"/>
    <add assembly ="netstandard, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = cc7b13ffcd2ddd51"/>
  </assemblies>
</compilation>