DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

NavigationManager

Sort:
You are not authorized to post a reply.
Page 1 of 3123 > >>





Veteran Member





    Hi all,

    I got a problem when replacing the Globals.NavigateURL() function with the new INavigationManager. What I have done:

    namespace myNamespace
    {
       public partial class myControl : PortalModuleBase, IActionable
       {
          [...]
          protected INavigationManager NavigationManager { get; }
          [...]
    #region IActionable
          public ModuleActionCollection ModuleActions
          {
             get
             {
                ModuleActionCollection actions = new ModuleActionCollection();
                switch (someCondition)
                {
                    case [...]:
                       [...]
                       break;
                    case [...]:
                       actions.Add(GetNextActionID(),
                          Localization.GetString("ActionName", LocalResourceFile),
                          ModuleActionType.AddContent,
                          string.Empty,
                          string.Empty,
                          NavigationManager.NavigateURL(string.Empty, new string[] { "parameter=value" }),
                          false,
                          SecurityAccessLevel.Edit,
                          true,
                          false);
                       break;
                    [...]
                }
                return actions;
             }
          }
    #endregion
       }
    }
    
    

    I get a null reference exception (NavigationManager is null). What did I miss?

    Happy DNNing!
    Michael

    Michael Tobisch
    DNN★MVP

    dnnWerk Austria
    DNN Connect





    Advanced Member





      Since WebForms don't have Dependency Injection support, you have to set that property (in an MVC or Web API controller, you would add INavigationManager as a constructor parameter, and the DI support would automatically supply it).  In the control's constructor, set that property to DependencyProvider.GetRequiredService(). See this WebForms example or the Use the Service Locator section of Andrew's WebForm DI blog post.

      DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase





      Veteran Member





        Thank you, Brian!

        Happy DNNing!
        Michael

        Michael Tobisch
        DNN★MVP

        dnnWerk Austria
        DNN Connect





        Veteran Member





          Hi Brian,

          I tried this, but here I get an error: Method must have a return type.

          Any idea? Do I have to install a NuGet package for that, and if yes, where do I find it? Is it this one? How can I install it from there? Or is it on the public NuGet feed (from Andrews blog: "Once DNN 9.4 is released it will be available on the public NuGet Feed."). Where is that? I did not find anything with the VS NuGet manager... :-(

          Happy DNNing!
          Michael

          Michael Tobisch
          DNN★MVP

          dnnWerk Austria
          DNN Connect





          Advanced Member





            That's the constructor, so you'll need to add that line to your constructor, or if you don't already have a constructor, use the name of your control's class instead of View
            DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase





            Advanced Member





              Also, adding DNN 9.4 NuGet packages should automatically pull in DotNetNuke.Abstractions and DotNetNuke.DependencyInjection
              DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase





              Veteran Member





                Posted By Brian Dukes on 23 Jan 2020 09:39 AM
                That's the constructor, so you'll need to add that line to your constructor, or if you don't already have a constructor, use the name of your control's class instead of View

                Stupid me! Too much trees to see the forest...

                Thanks for your help.

                Happy DNNing!
                Michael

                 

                 

                Michael Tobisch
                DNN★MVP

                dnnWerk Austria
                DNN Connect





                Veteran Member





                  Posted By Brian Dukes on 23 Jan 2020 09:40 AM
                  Also, adding DNN 9.4 NuGet packages should automatically pull in DotNetNuke.Abstractions and DotNetNuke.DependencyInjection

                  Hi Brian,

                  I still have problems, I can't find any DNN packages when browsing using the NuGet Packet Manager (in VS 2019).

                  Anyway, I set the references to DotNetNuke.Abstractions, DotNetNuke.DependenyInjection and Microsoft.Extensions.DependencyInjection manually, but still get this error:

                        public MyView()
                        {
                           NavigationManager = DependencyProvider.GetRequiredService<INavigationManager>();
                        }
                  
                  

                  'IServiceProvider' does not contain a definition for 'GetRequiredService' and no accessible extension method 'GetRequiredService' accepting a first argument of type 'IServiceProvider' could be found (are you missing a using directive or an assembly reference?)

                  Any ideas?

                  Happy DNNing!
                  Michael

                  Michael Tobisch
                  DNN★MVP

                  dnnWerk Austria
                  DNN Connect





                  Advanced Member





                    GetRequiredService is an extension method, so you'll need to add using Microsoft.Extensions.DependencyInjection;.

                    Here's the DotNetNuke.Core NuGet package, which depends on DotNetNuke.DependencyInjection. In the NuGet dialog, is the Package source drop down mistakenly set to a custom feed instead of All or nuget.org?

                    DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase





                    Veteran Member





                      Hi Brian,

                      [...]
                      using DotNetNuke.DependencyInjection;
                      [...]
                      using Microsoft.Extensions.DependencyInjection;
                      [...]
                      
                      

                      are both set, but appear in gray (not used) in the source code.

                      There are also references to the two DLLs in the bin folder, DotNetNuke.DependencyInjection (v 9.4.4.0) and Microsoft.Extensions.DependencyInjection (v 2.1.1.0).

                      Happy DNNing!
                      Michael

                      Michael Tobisch
                      DNN★MVP

                      dnnWerk Austria
                      DNN Connect
                      You are not authorized to post a reply.
                      Page 1 of 3123 > >>

                      These Forums are dedicated to the discussion of DNN Platform.

                      For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

                      1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
                      2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
                      3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
                      4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
                      5. No Flaming or Trolling.
                      6. No Profanity, Racism, or Prejudice.
                      7. Site Moderators have the final word on approving / removing a thread or post or comment.
                      8. English language posting only, please.

                      Would you like to help us?

                      Awesome! Simply post in the forums using the link below and we'll get you started.

                      Get Involved