I have a class file (Facility.vb) in my MVC project root containing a single class (Facility). One of the properties of my ViewModel which I pass to the View is a List(Of Facility).
In my View, I iterate through each Facility like so:
@For Each f As Object In Model.Facilities
...
Next
This works fine but if I use Facility instead of Object then it tells me it is undefined.
I would appreciate it if someone could point me in the right direction!
davejuk
Member
39 Points
12 Posts
Unable to access a Class from my View
Jun 18, 2012 03:23 PM|LINK
I have a class file (Facility.vb) in my MVC project root containing a single class (Facility). One of the properties of my ViewModel which I pass to the View is a List(Of Facility).
In my View, I iterate through each Facility like so:
@For Each f As Object In Model.Facilities
...
Next
This works fine but if I use Facility instead of Object then it tells me it is undefined.
I would appreciate it if someone could point me in the right direction!
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: Unable to access a Class from my View
Jun 18, 2012 03:26 PM|LINK
instead try
@For Each f As Facility In Model.Facilities
...
Next
or
@For Each f In Model.Facilities
...
Next
davejuk
Member
39 Points
12 Posts
Re: Unable to access a Class from my View
Jun 18, 2012 03:31 PM|LINK
Thank you for the quick reply - the first one was what I was using and getting the error.
I didn't think to try it without a datatype but that has done the trick.
Why would I not be able to use @For Each f As Facility In Model.Facilities ?
Unnics
Member
394 Points
93 Posts
Re: Unable to access a Class from my View
Jun 18, 2012 03:37 PM|LINK
Hi you can use the fully qualified name space to get the reference of your class in the view.
If the class "Facility " is in the name space "ABC",
then you will be able to get the referenece by ABC.Facility
so that you will be able to
@For Each ABC.Facility f In Model.Facilities
...
Next
Hope this will help.