ASP.NET MVC - How to create a strongly-typed view from classes in referenced class-library?
Asked Answered
G

5

5

i'm trying to create a strongly-typed view using Visual Studio 2008. I can right-click a controller action and choose: Add view... In the next dialog window there is an option 'Create a strongly-typed view'. If I check this option I can select a list of classes that are in my current project.

However I cannot select the class I need which is in a class-library that I referenced.

  • The classlibrary is a strongly-typed assembly which is loaded in the GAC.
  • Obviously the library is referenced in the project.
  • I've added a <add namespace="namespace" /> in web.config
  • I've rebuilt multiple times, and restarted VS
  • Classlibrary doesn't have any problems...

Any suggestions?

Gentoo answered 12/5, 2009 at 12:58 Comment(1)
Any solution? please update here.Ernest
Y
3

Just create you view with any of the model classes then manually edit ASPX and replace the model class with the one you want. Probably the dialog window is just not intelligent enough.

But in my personal opinion, using "outside" classes as your models is very wrong.

All models, views and controllers should be here, directly in your project. They then can use internally whatever they need wherever it is.

Yttrium answered 12/5, 2009 at 13:2 Comment(2)
I agree that I shouldn't use outside classes. However this -should- work. It is a read-only classlibrary which has collections and entities built-in. I like your suggestion of manually replacing, but this doesn't work, I get a compilation error probably because the inheritance is messed up: 'Title' is not a member of 'ASP.views_home_list_aspx'Gentoo
The error I received is not related to my question. Your suggestion works. Thanks!Gentoo
E
8

This is surely to late for answering this question,but for future readers:

i noticed that very often i have to build->clean solution and then to build->rebuild solution and the classes magically appear (as they should)

Elissa answered 29/1, 2010 at 17:48 Comment(1)
While I'm not sure that this particular answer solves the question as posed, it solves my mostly related problem, so thank you!Sordello
Y
3

Just create you view with any of the model classes then manually edit ASPX and replace the model class with the one you want. Probably the dialog window is just not intelligent enough.

But in my personal opinion, using "outside" classes as your models is very wrong.

All models, views and controllers should be here, directly in your project. They then can use internally whatever they need wherever it is.

Yttrium answered 12/5, 2009 at 13:2 Comment(2)
I agree that I shouldn't use outside classes. However this -should- work. It is a read-only classlibrary which has collections and entities built-in. I like your suggestion of manually replacing, but this doesn't work, I get a compilation error probably because the inheritance is messed up: 'Title' is not a member of 'ASP.views_home_list_aspx'Gentoo
The error I received is not related to my question. Your suggestion works. Thanks!Gentoo
I
1

This was posted a long time ago but my solution might help someone....

I just had this same problem and I found that if I had "Controller" as part of the class name - I had a "DoorController" - I could not add it via the strongly-typed view selection. It also caused me other problems in asp mvc.

This might hold true for "Model" and "view" also? Try changing your model's class name to fix this issue.

Illfated answered 8/2, 2011 at 17:34 Comment(0)
E
0

I'm not sure if my own classes show up in the list or not - I usually just type them (starting from the root namespace). What happens if you try to type in for example MyRootNamespace.MyClassLibrary.MyNamespace.AnotherNamespace.TheClass in the textbox and click OK?

Endbrain answered 12/5, 2009 at 13:11 Comment(1)
I can manually type the classname including namespaces, however the view content dropdown is then disabled...Gentoo
F
0

I can manually type the classname including namespaces, however the view content dropdown is then disabled... – ropstah May 12 at 13:31

I'm having the same problem with my custom-created Data Classes. They show up in the "View Data Class" drop down but the "View Content" drop down is disabled. I'm guessing that my classes need to implement some interface. I'm just not sure which one.

Foist answered 21/8, 2009 at 12:49 Comment(1)
You might want to check this: msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx . A very good ORM tool is Entityspaces, www.entityspaces.comGentoo

© 2022 - 2024 — McMap. All rights reserved.