Attempting to add a strongly typed view does not f

2019-03-18 13:57发布

I have a very odd problem. Whenever I try to use the "Add View" dialog in ASP.NET MVC2 and then try to "Create 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:

http://imgur.com/47itE.png

5条回答
老娘就宠你
2楼-- · 2019-03-18 14:14

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.

查看更多
你好瞎i
3楼-- · 2019-03-18 14:27

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

查看更多
戒情不戒烟
4楼-- · 2019-03-18 14:30

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

查看更多
冷血范
5楼-- · 2019-03-18 14:35

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

查看更多
别忘想泡老子
6楼-- · 2019-03-18 14:35

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.

查看更多
登录 后发表回答