如何在ASP.NET MVC项目中获得“添加控制器”和“添加视图”菜单选项?

时间:2021-04-21 04:09:24

I added ASP.NET MVC manually to an existing WebForms application... thanks to this tutorial.

我手动将ASP.NET MVC添加到现有的WebForms应用程序中...感谢本教程。

However, now I do not have the menu options (When right-clicking on the Controllers folder or Views folders) to show the Add Controller or Add View dialog boxes. I do have this when creating a brand new MVC project. How can I get visual studio to realize I am using MVC in this mixed project?

但是,现在我没有菜单选项(右键单击Controllers文件夹或Views文件夹时)以显示Add Controller或Add View对话框。在创建一个全新的MVC项目时,我确实有这个。我怎样才能让visual studio意识到我在这个混合项目中使用MVC?

6 个解决方案

#1


Technically controllers are just .CS files that are put in the controllers folder and views are just .ASPX files that are put in the views folder. Your controllers classes need to inherit from the base Controller class and your ASPX page needs to inherit from System.Web.Mvc.ViewPage.

技术上控制器只是放在controllers文件夹中的.CS文件,视图只是放在views文件夹中的.ASPX文件。您的控制器类需要从基本Controller类继承,并且您的ASPX页面需要从System.Web.Mvc.ViewPage继承。

As far as getting those items in your menu though try opening your project file and replacing the projecttypeguids tag with this one.

至于在菜单中获取这些项目,但尝试打开项目文件并将projecttypeguids标记替换为此项目。

<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

#2


In order to fix your machine, go to the URL at http://www.microsoft.com/en-us/download/details.aspx?id=41532 and make sure you install both "ASP.NET and Web Tools 2013.1 for Visual Studio 2012" and "ASP.NET and Web Frameworks 2013.1 - Visual Studio 2012".

要修复您的计算机,请转到http://www.microsoft.com/en-us/download/details.aspx?id=41532上的URL,并确保同时安装“ASP.NET和Web Tools 2013.1 for Visual Studio 2012“和”ASP.NET和Web框架2013.1 - Visual Studio 2012“。

After installation you should have them both in your installed programs list.

安装完成后,您应该将它们放在已安装的程序列表中。

For more details you can check this URL: http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx.

有关详细信息,请查看以下URL:http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1 - 用于视觉工作室,2012.aspx。

The Project Type GUID thing is just a workaround. But it will automatically be removed after you install these.

项目类型GUID的事情只是一种解决方法。但是在安装后会自动删除它。

#3


I got this same problem, except I started off cleanly with an Asp.Net MVC project. Don't know why this is happening. While I realize full well what controllers are(Harv) I still desire the auto-generation that the context-senstive menu options offer. CS menu's are not appearing in Solution Explorer or in the document window when editing the controller file, according to Walther video, he simply right-clicks on the Index method and he gets a cs menu option to create a view, an Add View dialog window. Oh BTW, my project guids are identical to the ones you provided, so that didn't help.

我遇到了同样的问题,除了我开始干净利落的Asp.Net MVC项目。不知道为什么会这样。虽然我完全清楚控制器是什么(Harv),但我仍然希望上下文感应菜单选项提供的自动生成。在编辑控制器文件时,CS菜单没有出现在解决方案资源管理器或文档窗口中,根据Walther视频,他只需右键单击Index方法,他就会获得一个cs菜单选项来创建一个视图,一个Add View对话框窗口。哦顺便说一句,我的项目指南与你提供的那些相同,所以这没有帮助。

Thanks, Berlioz

#4


Do nothing just update your MVC project version. Fire this command in your Nuget Package Manager console.

什么都不做只是更新您的MVC项目版本。在Nuget Package Manager控制台中触发此命令。

Update-Package Microsoft.AspNet.Mvc

Restart your visual studio project.

重新启动visual studio项目。

Also don't forgot this. For resolving this error

也别忘了这个。用于解决此错误

Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'

通过安全透明方法'WebMatrix.WebData.PreApplicationStartCode.Start()'尝试

Install-Package -Id Microsoft.AspNet.WebHelpers

Install-Package -Id Microsoft.AspNet.WebHelpers

#5


I had this issue in Visual Studio Enterprise 2015 update1 and was resolved by installing the latest update.

我在Visual Studio Enterprise 2015 update1中遇到此问题,并通过安装最新更新得到解决。

#6


ASP.NET MVC prefers convention over configuration so there's really no way other than Harv's answer to be able to set it up. You have to right-click a folder named Controllers and a folder named Views to get those options.

ASP.NET MVC更喜欢约定优于配置,所以除了Harv的答案之外,别无法设置它。您必须右键单击名为Controllers的文件夹和名为Views的文件夹才能获取这些选项。

#1


Technically controllers are just .CS files that are put in the controllers folder and views are just .ASPX files that are put in the views folder. Your controllers classes need to inherit from the base Controller class and your ASPX page needs to inherit from System.Web.Mvc.ViewPage.

技术上控制器只是放在controllers文件夹中的.CS文件,视图只是放在views文件夹中的.ASPX文件。您的控制器类需要从基本Controller类继承,并且您的ASPX页面需要从System.Web.Mvc.ViewPage继承。

As far as getting those items in your menu though try opening your project file and replacing the projecttypeguids tag with this one.

至于在菜单中获取这些项目,但尝试打开项目文件并将projecttypeguids标记替换为此项目。

<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

#2


In order to fix your machine, go to the URL at http://www.microsoft.com/en-us/download/details.aspx?id=41532 and make sure you install both "ASP.NET and Web Tools 2013.1 for Visual Studio 2012" and "ASP.NET and Web Frameworks 2013.1 - Visual Studio 2012".

要修复您的计算机,请转到http://www.microsoft.com/en-us/download/details.aspx?id=41532上的URL,并确保同时安装“ASP.NET和Web Tools 2013.1 for Visual Studio 2012“和”ASP.NET和Web框架2013.1 - Visual Studio 2012“。

After installation you should have them both in your installed programs list.

安装完成后,您应该将它们放在已安装的程序列表中。

For more details you can check this URL: http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx.

有关详细信息,请查看以下URL:http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1 - 用于视觉工作室,2012.aspx。

The Project Type GUID thing is just a workaround. But it will automatically be removed after you install these.

项目类型GUID的事情只是一种解决方法。但是在安装后会自动删除它。

#3


I got this same problem, except I started off cleanly with an Asp.Net MVC project. Don't know why this is happening. While I realize full well what controllers are(Harv) I still desire the auto-generation that the context-senstive menu options offer. CS menu's are not appearing in Solution Explorer or in the document window when editing the controller file, according to Walther video, he simply right-clicks on the Index method and he gets a cs menu option to create a view, an Add View dialog window. Oh BTW, my project guids are identical to the ones you provided, so that didn't help.

我遇到了同样的问题,除了我开始干净利落的Asp.Net MVC项目。不知道为什么会这样。虽然我完全清楚控制器是什么(Harv),但我仍然希望上下文感应菜单选项提供的自动生成。在编辑控制器文件时,CS菜单没有出现在解决方案资源管理器或文档窗口中,根据Walther视频,他只需右键单击Index方法,他就会获得一个cs菜单选项来创建一个视图,一个Add View对话框窗口。哦顺便说一句,我的项目指南与你提供的那些相同,所以这没有帮助。

Thanks, Berlioz

#4


Do nothing just update your MVC project version. Fire this command in your Nuget Package Manager console.

什么都不做只是更新您的MVC项目版本。在Nuget Package Manager控制台中触发此命令。

Update-Package Microsoft.AspNet.Mvc

Restart your visual studio project.

重新启动visual studio项目。

Also don't forgot this. For resolving this error

也别忘了这个。用于解决此错误

Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()'

通过安全透明方法'WebMatrix.WebData.PreApplicationStartCode.Start()'尝试

Install-Package -Id Microsoft.AspNet.WebHelpers

Install-Package -Id Microsoft.AspNet.WebHelpers

#5


I had this issue in Visual Studio Enterprise 2015 update1 and was resolved by installing the latest update.

我在Visual Studio Enterprise 2015 update1中遇到此问题,并通过安装最新更新得到解决。

#6


ASP.NET MVC prefers convention over configuration so there's really no way other than Harv's answer to be able to set it up. You have to right-click a folder named Controllers and a folder named Views to get those options.

ASP.NET MVC更喜欢约定优于配置,所以除了Harv的答案之外,别无法设置它。您必须右键单击名为Controllers的文件夹和名为Views的文件夹才能获取这些选项。