DNN Forums

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

NavigationManager

 24 Replies
 3 Subscribed to this topic
 26 Subscribed to this forum
Sort:
Page 1 of 3123 > >>
Author
Messages
Veteran Member
Posts: 1182
Veteran Member
MVP
MVP
You're an MVP!

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

DNN Connect
Advanced Member
Posts: 159
Advanced Member
MVP
MVP
You're an MVP!

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

Veteran Member
Posts: 1182
Veteran Member
MVP
MVP
You're an MVP!
Thank you, Brian!

Happy DNNing!
Michael

Michael Tobisch
DNN★MVP

DNN Connect
Veteran Member
Posts: 1182
Veteran Member
MVP
MVP
You're an MVP!

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

DNN Connect
Advanced Member
Posts: 159
Advanced Member
MVP
MVP
You're an MVP!
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
Advanced Member
Posts: 159
Advanced Member
MVP
MVP
You're an MVP!
Also, adding DNN 9.4 NuGet packages should automatically pull in DotNetNuke.Abstractions and DotNetNuke.DependencyInjection
Veteran Member
Posts: 1182
Veteran Member
MVP
MVP
You're an MVP!
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

DNN Connect
Veteran Member
Posts: 1182
Veteran Member
MVP
MVP
You're an MVP!
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

DNN Connect
Advanced Member
Posts: 159
Advanced Member
MVP
MVP
You're an MVP!

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

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?

Veteran Member
Posts: 1182
Veteran Member
MVP
MVP
You're an MVP!

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

DNN Connect
Page 1 of 3123 > >>

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

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