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:
In this quick article you will learn about Strongly Typed Views in MVC. When you add a new View in MVC, you get an opportunity to create it strongly typed. In the image given below, when you check "Create a strongly-typed view" and select the "Model class" you get the following code snippet on the view page.
Strongly typed Views is considered as a better approach since we already know what data is being passed as the Model unlike dynamic typed Views in which the data gets bind at runtime and may lead to runtime errors, if something changes in the linked model.
Then the question that should come to your mind is how we will pass the Header to a strongly typed view without using ViewBag. Well, we can do this by using the View Model in the ASP.NET MVC application. In our next article, I am going to discuss the View Model in the ASP.NET MVC application with Example.
So Modify the Index.cshtml view file as shown below to make the view as strongly typed. That’s it. Now run the application and navigate to the “/Home/Index” URL and you will see the employee data as expected in the webpage.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With