开发者

Attempting to add a strongly typed view does not find any classes in the MVC project

开发者 https://www.devze.com 2023-01-17 09:28 出处:网络
I have a very odd problem. Whenever I try to use the \"Add View\" dialog in ASP.NET MVC2 and then try to \"Cr开发者_运维问答eate a strongly-typed view\" by selecting a \"View data class\" from the dro

I have a very odd problem. Whenever I try to use the "Add View" dialog in ASP.NET MVC2 and then try to "Cr开发者_运维问答eate a strongly-typed view" by selecting a "View data class" from the drop down of available classes none of the classes ("models") in my MVC project are showing up.

The very odd part is all of the assemblies that my MVC project is referencing, even other projects in the solution, their classes are showing up. I have tried cleaning, rebuilding, cleaning the obj folder but every single time for some reason none of the classes in my actual MVC assembly are showing up. It was working fine before but now it doesn't anymore and I can't really think of anything that has changed.

Anyone experienced this issue before? Thanks for the help!

Image of example:

Attempting to add a strongly typed view does not find any classes in the MVC project


Its Because you have not build your application, First build your application and then make a view then it will show .


Figured this out, here is the solution:

The MVC Project was referencing a bunch of service contract assemblies that where referencing a "CommonServiceContractAssembly.dll". The MVC Project was also referencing "CommonServiceContractAssembly.dll". The MVC Project and the service contract assemblies were all built referencing slightly different versions of "CommonServiceContractAssembly.dll"

When Visual Studio 2010 was reflecting on all referenced assemblies to "Create a strongly-typed view" of I believe it wasn't sure how to handle the slightly different version of "CommonServiceContractAssembly.dll" being referenced so it didn't display the reflected "strongly typed model" possibilities for any assemblies dependent on "CommonServiceContractAssembly.dll".

The fix is to actually force Visual Studio 2010's app domain to use the correct version of "CommonServiceContractAssembly.dll" when Visual Studio 2010 starts up. This was accomplished with a Post Build Event like the following:

REM This is required for T4 generation from models to work properly copy "$(TargetDir)"CommonServiceContractAssembly.dll" "$(DevEnvDir)PublicAssemblies\" /Y

So I copy "CommonServiceContractAssembly.dll" that is referenced "everywhere" into where Visual Studio will load it. After I did this everything worked properly.

Another option would be to always ensure that all assemblies that share a common dependency are always compiled with the same version of that dependency.


Please make sure that you are marking them as "Public", and compile it once before opening the AddView Dialog box.


Some types from your project are filtered out by that dialog (for example all types ending in 'Controller', or all types in the System or Microsoft namespace). It's possible that your project does not have any types that would pass through the dialog's filters.


Before Adding View just Build the solution and then add view it will work. if it will not work then you can again concern with me i will give you another solution

0

精彩评论

暂无评论...
验证码 换一张
取 消