views:

53

answers:

2

Ok this seems like an easy one:

In c# asp.net mvc I can declare some public class like:

public class Foo {
   public static string Bar {get
   {return "bar";}
   }
}

and access it from any html like:

<%=Foo.Bar;%>

right?

Well, I have to do the same in ASP.NET MVC VB.Net but I cannot access any variable or method:

public class Foo
   public Shared ReadOnly Bar as string
   Get
      return "Bar"
   end Get
   End Property
End Class

trying to do <%=Foo.Bar;%> does not work in vb.net I get Name 'Foo' is not declared.

What am I missing here?

A: 

Recompile you project

oh and your property is missing the property keyword

try this :

    Public Shared ReadOnly Property Bar As String
    Get
        Return "Bar"
    End Get
    End Property
Yassir
Ofcourse I've compiled my project, the code you see is pseudo code. I'm wouldn't create a foo bar class in the real world.
Elger
Do you have a refrence to the assembly in your web.config ?
Yassir
A: 

Ok standard VB.NET puts modules in the namespace defined in your project.

I had to type

MVCApplication1.Foo.Bar

Any suggestions on how to create a module that doesn't wrap this into a namespace? Or have the view import the application namespace by default?

Elger
Oh I can answer that question myself too:in the web.config:<add namespace="MVCApplication1"/>
Elger