2

I have a module written in VB.Net that has several read-only properties. It looks like this:

Module Name1
   Public ReadOnly Property ClientID As String
      Get
         Return "[some data here]"
      End Get
   End Property

   Public ReadOnly Property ClientKey As String
      Get
         Return "[some data here]"
      End Get
   End Property
End Module

Nothing real fancy here. What I'm trying to do is use this module in an MVC 5 Razor page like this:

<span>@Name1.ClientID - @Name1.ClientKey</span>

Again, nothing fancy. But running the code produces the following error:

Name1 is not accessible in this context because it is 'Friend'.

Modules have friend access by default, which prevents them from being accessible outside of the current assembly. This is what I want. But it doesn't work when called from a Razor page. I've check to ensure that the namespaces were imported and such but no go. (Changing the module's access to public gets things working but I don't wish to make it public.)

What am I doing wrong?

GSerg
  • 76,472
  • 17
  • 159
  • 346
Dude-Dastic
  • 380
  • 1
  • 5
  • 13
  • Razor views are compiled into their own assembly. – GSerg Sep 02 '20 at 20:08
  • Does this answer your question? [Asp.net MVC3 access internal class from razor View](https://stackoverflow.com/questions/11630919/asp-net-mvc3-access-internal-class-from-razor-view) – GSerg Sep 02 '20 at 20:15
  • @GSerg That link does not help. All that would do is make the module public, meaning it'll be accessible outside of the current assembly, which is what I don't want. But your first reply tells me it's not possible to do what I want, so I'll have to find another way to accomplish my goal. – Dude-Dastic Sep 03 '20 at 12:47
  • Have you looked at https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.internalsvisibletoattribute mentioned in the second sentence? – GSerg Sep 03 '20 at 13:37
  • @GSerg Thanks for your help. I've already solved the issue. See answer below. – Dude-Dastic Sep 03 '20 at 16:15

1 Answers1

0

I found a solution to my problem here: ASP.NET MVC: How to set global ViewBag properties and have them available in each View

By creating a custom ActionFilter, I was able to set ViewBag properties and set their values to the properties in my module. Then I added that filter to the GlobalFilters collection. From there, I can access the ViewBag properties easily in Razor pages.

Dude-Dastic
  • 380
  • 1
  • 5
  • 13