visual studio razor views not recognizing model - visual-studio-2010

I have 2 instances of VisualStudio 2010 open and both projects are ASP.Net MVC and I'm using Razor view engine. In the first instance, views are recognizing #model value and I get intellisense. The second instance does not recognize the model for the view and no intellisense. I know i have the right namespace for the model because I can run the app and get results. What setting am I missing? Thank you.

Most likely an issue with MVC version and the configuration of dll's to use.
Make sure you have defined all the correct versions of the MVC dll's in the config files.
I had this same issue in Visual Studio 2013, upgraded project from MVC 3 to MVC 4, made sure every config was referencing the correct dll's versions and the problem was gone.

I just fought through this with VS2013 today; the .csproj file had set all of the references to Private (=True) and confused itself that way. Eliminating all of the Private markers (and setting SpecificVersion = False) got Visual Studio thinking clearly again.
The references are once again showing up as Private = True, but the Razor syntax hasn't broken down again (yet).

Related

Cannot add view to ASP.NET MVC 5 project

I'm trying to add a view to an ASP.NET MVC 5 project in Visual Studio 2013, but the Add button is greyed out.
The default installation of Visual Studio was missing some required elements. When I chose ASP.NET and web development, the following options were not selected on the right side of the page.
.NET Framework project and item templates
NET Framework 4.6.2-4.7.1 development tools
Additional Project templates (previous versions)
.NET WebAssembly build tools
(I found this on the Microsoft web site Microsoft Developer Resources (in spanish!)
I got this for ages, all I did was upgrade the nuget packages for Mvc and it fixed it. I suspect that I had a mismatch of versions in the solution.
Update-Package Microsoft.AspNet.Mvc -Version 5.2.3
The version part is optional, but it should mean that all projects get the same version.
You should create a controller first, then it will create a View folder automatically. Try to right click that file then click create new view. Also Copy might be a specific name, you may need to change that name.
Different from the OP issue (as I'm on VS2017) but in case anyone else comes to this question when they've made the same (basic) error as me...
It took me a few minutes to realise that if you type in a new Model class (as seen below) then this is not what the UI wants; it requires you to select an existing Model from the dropdown. Once I created the model and then selected it 'Add' was enabled.

How to Use Entity Framework 4 with Visual Studio 2013

We have recently upgraded our Visual Studio from 2010 to 2013. With it came EF 6.0, which is incompatible with the code generated from EF 4.
I need to update a table in the model with the latest version from the DB schema. When doing that, both "Update" and "Add" after deletion of the table definition do the following:
Remove all custom code already written for all types in the model, even if they are in separate files than the model;
Generate the new EF 6.0 bindings;
(optionally) Generate the new repository.
Now, that's obviously not the same behavior as in EF 4, which only regenerated the repository and did not touch the custom code.
We are not using NuGet, but referencing the EF library inside the project.
I guess VS 2013 uses a different version of the code generator than VS 2010. How can we revert to the old behavior?
UPDATE:
I have tried using NuGet to download EF 4.3.1 and repeat the update model steps (also delete and then recreate), but I am still seeing the old behavior. I think there is a problem with the VS 2013 EF Code Generator.
For me, the following solution worked.
Double-click on your edmx file and open its properties window. Change Code Generation Strategy from T4 to Legacy Object Context. Build your solution. It may cause thousands of errors because you have redeclared functions and properties, so remove all files that weren't there before.

VS 2013 and MVC 5 - class for view set in web.config ignored by intellisense

I have a number of extension methods on System.Web.Mvc.HtmlHelper. They all work, the pages load up just fine. No compilation errors nor runtime errors. I am using my own derived view class, derived from System.Web.Mvc.WebViewPage< T >
The issue is intellisense in these views are not showing my extension methods as available. In fact they're not showing anything as available from my derived view class. When I go to definition on the #Html it shows that VS is looking at System.Web.WebPages.HtmlHelper.
Is there a way to correct this and have Visual Studio recognize the base class I'm using? Once again this all builds correctly and runs just fine, everything works as expected.
Additional info while researching this:
It looks like tooling support for VS 2012 and MVC 5 has yet to be released and is currently expected to be released in mid-november. Source. This may indicate the support isn't complete in VS2013 as well.
When you upgrade to MVC5 through Nuget, there are a number of files that need to be edited in order to ensure that your application builds and runs correctly, and has support for the right tooling.
All of this information is captured in this Microsoft guide for upgrading from ASP.NET MVC 4 to ASP.NET MVC 5. Please note that if you read the comments of the guide, there is still an issue with VS2012's tooling due to what VS2012 expects versus the updates to the way the new toolchain attempts to find binaries. A patch is expected for MVC5 support in VS2012 by November 2013.
Hopefully following the steps in the guide help you solve your issue. They worked fine for me. (Note that I started from a base project and attempted to upgrade it in VS2013. I did not start with an existing project.)

Conversion of MVC 2 project in VS2008 to VS 2010.. failure on one project.. Project type wrong?

So I'm trying to take a VS2008 MVC1 project to MVC3.
Here are the steps I'm trying to do.
Use conversion to to convert vs2008 mvc1 to vs 2008 mvc2 (success)
Tool: http://weblogs.asp.net/leftslipper/archive/2010/03/10/migrating-asp-net-mvc-1-0-applications-to-asp-net-mvc-2-rtm.aspx
Open vs2008 sln in vs2010 to convert (failed on my main app project)
Convert from .Net3.5 to .Net 4.0
Use tool to covert to MVC3
On step two, it fails on my main project, and then will not open the project with the error.
The Project <project path> cannot be opened
The project type is not supported by this installation
I found some StackOverflow posts abotu similar issue with RC1 and RC2, but installaed my MVC2 from the webplatform installer and so it should eb the latest, not the RC.
I assume this line is my problme, anyone know how to fix it?
<ProjectTypeGuids>{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
I tried posting my csproj, but it excedded the max lines.. if there is a part neede to diagnose this just let me know.
Thanks,
Cal-
Personally I use the following migration path *:
Ensure that I have ASP.NET MVC 3 RTM Tools Update installed
Open the ASP.NET MVC 1.0 project in Visual Studio 2010
The migration wizard kicks in and asks me if I want to convert to .NET 4.0 and I say Yes
Make sure that the System.Web.Mvc assembly referenced in my project is V2.0.0.0. If it is still the old I remove it and add the correct version
At this stage I ensure that I have a working ASP.NET MVC 2.0 application and close Visual Studio.
There is one final step left. For it, depending on my mood, I do one of the following:
Do the migration manually by following the upgrade guide
Use the ASP.NET MVC 3 Project Upgrade Tool
* To answer this question I did the previous steps on a real ASP.NET MVC 1.0 project and it was successfully upgraded to ASP.NET MVC 3
Okay I did it both ways and got the same result.
I did figure it out, here's what was going on. Be aware that steps 1 and 3 are probably all that's needed to fix it, but I'm including step two, both for clarity of my debugging process and completeness in case it's required and my assumptions are false.
Even though MVC# was installed, and showed as installed in the Add removed programs, MVC 3 was not showing up as a reference. I unininstalled, reinstalled and rebooted and it started showing up.
I had to modify the project Type Guids in he CSPROJ file, first I deleted them one at a time till the Main app project was able to load, then I recovnerted. All projects except the main one worked, but it didnt' convert. It did not covnert becuase of an unrecognized project Type Guid.
Becasue it didnt convert I got this error:
The type 'System.Web.Mvc.ViewMasterPage' is ambiguous: it could come from assembly 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Mvc\v4.0_3.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll' or from assembly 'C:\Windows\assembly\GAC_MSIL\System.Web.Mvc\1.0.
Note the Coverted did not throw and error, it merely logged that the project did not get convereted. You have to look at the logs carefully to notice.
Luckily you can run the converter on the same soloution multiple times. that's how I noticed this.
I had to modify the Project Type guids again, because of the unrecognized type guid again. I just created a new MVC3 project and edited the CSPROJ to get the correct type guids.
{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
Note: this is what the guids already looked like, but I copied them from an existing good project and pasted them in the file and it started working, my best guess is there was an invisible character put in there by the conversion process.
After this I reconverted and it worked perfectly, and the errors went away.
Thanks,
Cal-

I'm upgraded my project to Razor view engine, but VS2010 still auto-generates WebForms

I have upgraded to MVC3 and Razor, everything works fine. However, in my return View(model); the "View" is red and VS2010 will helpfully suggest I generate a view. When I do, it generates a aspx/WebForms view. There's no other aspx files in the project, and if I run the project, the Razor view engine works fine. There's obviously a setting somewhere that tells VS2010 which to default to, I can't find it. Any suggestions?
These are not explicit answer but rather a list of actions that you could try..
In the csproj file of your project make sure that the <ProjectGuidType> are set to <ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
Try changing the ProjectGuid to some other Guid (last post). You will need to update the sln file or simply recreate the solution.
Not sure what method you used to upgrade, but have a look at the MVC 3 Upgrade Tool from CodePlex
If you can create a new ASP.NET MVC 3 project and add a Razor view as expected then the project where you are seeing this behavior is missing the ASP.NET MVC 3 project type guid, which you can find in a new ASP.NET MVC 3 project's .csproj file. If you can't do this than you should try reinstalling the ASP.NET MVC 3 Tools Update.

Resources