change webforms to mvc in visualstudio 2010 - asp.net-mvc

i created a blank webforms project instead of an MVC 3 project in visual studio, everything runs fine but i dont have my menues
for example when i right click on the Controllers folder i dont get "Add a controller" option.
does anyone know without starting a new project how to change the type of project into an MVC one so that i get the correct menus.
thanks

It's not that you don't have the menu options, it's that it's a completely different type of [web] application and works in different ways. e.g. Webforms has no concept of controllers so even if you did have a menu option it wouldn't get included in the project as you're expecting.
Because webForms and MVC are so different there could never be a 100% reliable conversion utility.
Just create a new project and copy the files already created. I can't imagine you've written that much code before realising that you're in WebForms, not MVC.
If you have got lots of WebForms code you could always just include this in the MVC project until you can convert it (if necessary) at a later time.
Edit:
If you just want to change the project type you can edit the csproj file of the webforms project and add the following ProjectTypeGuid {F85E285D-A4E0-4152-9332-AB1D724D3325};.
You'll need to update references, files, etc. for this to work but it may be quicker than creating a new project and copying content over. (Especially if you already have the project in source control.)
Note that I've only tested this going from WebForms 4 to MVC2.

Try updating a MVC to ASP.NET Fall Update Release Candidate. There is a link .

Related

Visual Studio Update 2015, many options for ASP.NET MVC project missing

I just installed Visual Studio 2015 Update 1, and a lot of the configuration I was used to is missing or different. I'd like to know if these changes are due to something simple (like a package I need to install), or if it's something a little more complex.
I'm mainly using Visual Studio to create MVC apps from scratch, so before the update, I would create an empty MVC app with the "Add core references and folders for MVC" selected. Now, I can only create an empty MVC project with nothing pre-configured, or a fully scaffolded MVC app.
In the empty MVC project, there's no option to "Add Controller" when I right-click the "Controllers" folder I create. However, this option is available in the generated one.
The Add New Item menu is divided into Server-side and Client-side templates for the generated app, but it's divided into Code/Data/General/Web/etc. in the empty app. There's also an option to add an MVC View in the generated app, but there's nothing with Razor for the empty app. No .cshtml intellisense in the empty app, either.
There's a lot of functionality and options missing from the empty app that seem like they have to do with how the app is an MVC app, since they're available for the generated app. Is there a straightforward fix that will allow me to create an MVC app using Razor from an empty template?
Figured it out! I was using the ASP.NET 4.5.2 Empty Template, and choosing the ASP.NET 5 Template solved the problem.

Mixing MVC and Webforms - Displaying BOTH Context Menus

I have added MVC4 to an ASP.NET Webforms project in Visual Studio 2010.
I changed the .csproj's project type to that of an MVC4 project as detailed here:
Context menu to Add Controller/View missing
to give me the MVC specific context menus.
Now the ASP.NET Webforms context menus (such as add 'UserControl') are gone.
How can I hack VS2010 to give me both the MVC4 and ASP.NET context menus for a given project?
In short and officially: no, this is not possible (disclaimer: I'm a software engineer at Microsoft who used to work on Visual Studio + Blend, but now Internet Explorer).
In Visual Studio, a project only has a single type, and the "ASP.NET Web Application" (WebForms) and "ASP.NET MVC Application" (ASP.NET MVC) are two different project types - they're very similar and share common features, but are still different types.
The MVC project type does not have UserControls and other Items in the Add New Item dialog or context-menus because they're largely irrelevant and wouldn't work as you expect them to (granted, it is possible to have WebForms (and not just using .aspx files as Views)) but I don't think it's a good application-design decision.
Unofficially... the items that appear in the Add New Item dialog are specified in the registry. This is documented here: https://msdn.microsoft.com/en-us/library/bb165141.aspx however this information is intended for developers of new project types, rather than allowing users to modify their own (and certainly you're at risk of breaking your VS if we release another update which makes assumptions about how your Add New Item templates are configured).
If you want to do it this way - go ahead, but be careful, and make a note of everything you do so you can undo it.
Since the IDE is based on working in single mode, It seems we have 2 ways:
Attempt to use a configuration that is done an OR action between two project types, so we have both of them, but lack of true functionality is demanded :(
Write some lines of C++ code to change configuration immediately (based on tip here), so you have a switcher application to run when you want :)

Did VS2013 incorrectly upgrade my project files?

I had a solution that included both an ASP.NET MVC web project and a WebAPI project. The solution was created originally with VS2012, but I recently upgraded it to VS2013.
I just noticed when going to add a controller that I'm not getting the correct options in the right click menu. For instance if I go to the web project and right click the controllers folder, the option to add a controller isn't there. Instead I have add WebAPI controller. It's exactly the opposite for the WebAPI project.
Things seem to build and run ok so far, but it's going to be a pain manually adding things and I'm wondering if something else might break. Any idea why this is happening or how to fix it?
I would guess that project type is different in your csproj. Take a look at this question:
What is the significance of ProjectTypeGuids tag in the visual studio project file
Here is what I have on my machine for c# asp.net mvc project:
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
Take a look at your guids and see what they mean.
You could see the meaning of the different GUID in the register :
•HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Projects for
ProjectTypeGuids
•HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Packages for
packages reference by some project

Add View dialog does not work in an MVC 5 project that references an F# project

Using Visual Studio 2013, create a new ASP.NET Web Application project using the MVC template. Verify that the Add View dialog functions by right-clicking the "Views\Home" folder and choosing "Add... View".
Now add a new F# Library project to the solution. The Add View dialog should still function correctly.
Now add a project reference from the MVC project to the F# project by right-clicking the References folder, choosing Add Reference, Then browse to Solution...Projects on the left and checking the F# library project that you just added.
At this point, if you right-click the "Views\Home" folder and choose "Add... View" you will get an error in a pop-up alert box instead of the Add View dialog:
There was an error running the selected code generator: 'Object reference not set to an instance of an object.'
Workarounds include, but are hopefully not limited to:
Remove all your references to any F# projects every time you want to add a new view.
Unload any referenced F# projects, but leave the project references in place, every time you want to add a new view.
My questions are:
Are other people seeing this behavior, or is it just me?
Does anyone know of a better work-around than removing references or unloading F# projects?
Does anyone know if Microsoft is already working on fixing this? If not should this be reported to the F# team or the Visual Studio team?
Between this issue and the fact that it is still impossible to use NuGet to add an Entity Framework 6 reference to any F# project, I'm starting to get nervous about Microsoft's level of commitment to the F# language.
Not sure if this will help you but check the version of EntityFramework in your solution. I had two projects within my solution and for whatever reason, the web project had EF 6 and the class library project was EF 6.1. Once I uninstalled EF completely from the solution and reinstalled EF 6.1 on both project, the "Add new view" action started working.
I received the same error message when adding views or controllers in a C# & MVC multi-project solution, using EF 6.1 and VS2013 with Update 3. The problem was because the nuget "packages" folder was marked as read only, because it was checked into source control. I checked the entire folder out, making it editable, and it started working fine, allowing me to scaffold straight from VS.
I also received the error message in a web.api project because I forgot to add the Entity Framework connection string to the web.config (it was using Areas and EF was looking in the Area web.config, not the web.config in the root).

How do you activate the MVC templates in VS2008 from a WebForms App

I'm in the process of adding ASP.NET MVC to a WebForms app. One of the neat features of an ASP.NET MVC solution that you create from scratch is that a right click on the solution explorer and Add > New Item... will give a list of templates which include the MVC templates. However, in a WebForms app these templates don't appear.
I thought that there might be a setting in the .sln solution file that indicated that one was an ASP.NET MVC app but I couldn't find anything that that stuck out.
EDIT: To expand the question, how does Visual Studio know to add a "Controller..." menu item on to the "Add" menu when you right click on the Controllers folder in the Solution Explorer of an MVC app? Likewise it adds a "View..." menu item to the "Add" menu when you right click on the Views folder. Where does Visual Studio get this info from and how can I add those 2 folders to another web app and get the same functionality?
Ideas?
I believe that the logic for that is contained in the dll
Microsoft.VisualStudio.Web.ExtensionsUI
Which is registered in the Project template used when you create a new ASP.NET MVC project:
<WizardExtension>
<Assembly>
Microsoft.VisualStudio.Web.Extensions,
Version=9.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35
</Assembly>
<FullClassName>
Microsoft.VisualStudio.Web.Mvc.TemplateWizard
</FullClassName>
</WizardExtension>
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033\MvcWebApplicationProjectTemplatev1.cs.zip
You could probably also mess around with the Project Type Guids in your .xxproj file:
<ProjectTypeGuids>
{603c0e0b-db56-11dc-be95-000d561079b0};
{349c5851-65df-11da-9384-00065b846f21};
{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
Seem to be the default ones for an ASP.NET MVC project, compare those with the ones in your web application, and go from there.
However, in a lot of these circumstances I'd agree with gisresearch: it's often easier to create the more complex project (the MVC one) first, and then move the origininal into it.
Also, there's nothing to stop you having multiple projects hosted in the same web application - pull the common logic from the web application into a shared class library, and then reference that from a clean MVC app, with a slightly different namespace, and then merge the two sites within IIS, drop the dlls into a shared bin folder (or strongly name them and put them in the global assembly cache), share the images/scripts, and away you go - you just need to take care with the Global.asax, which would be common to both.
How about the other way around. Create an asp.net mvc project firstly, and then add your web form code over.
Here is an example of hybrid app by Scott Hanselman.
You may also consider to create one default asp.net mvc application and asp.net web form application, and then do a text compare of two projects to see what is the difference.
Like Zhaph mentioned, adding the ProjectTypeGuid worked for me. Unload the web project, edit, and add in the extra ProjectTypeGuid to the existing list.
{603c0e0b-db56-11dc-be95-000d561079b0};

Resources