更新时间:2023-02-25 16:50:13
在 2013 年 11 月 14 日更新了这个答案,在 VS2013 正式发布之后,以反映最终版本中的变化 -ds
对于 Visual Studio 2013(发布版)
注意:最终版本带回了添加控制器"上下文菜单.
简单的方法:
右键单击 MVC 项目中的Controllers"文件夹
Right Click on the "Controllers" folder in your MVC project
添加 > 控制器...
选择一个控制器模板.(我更喜欢 MVC 5 Controller Empty)
Choose a Controller Template. (I prefer MVC 5 Controller Empty)
替代方式:
右键单击 MVC 项目中的Controllers"文件夹
Right Click on the "Controllers" folder in your MVC project
添加 > 新的脚手架项目...
选择控制器模板
此方法还显示非控制器模板,例如视图、区域和更多使列表更长的 WebAPI 功能.
This method also displays non-controller templates such as views, areas, and more WebAPI features making the list longer.
对于 Visual Studio 2013(预览版和候选发布版)
注意:VS 2013 Preview 和 RC 不包括添加控制器"上下文菜单.
使用 Visual Studio 2013 + ASP.NET MVC 5 创建新控制器:
To create a new controller with Visual Studio 2013 + ASP.NET MVC 5:
???可以是空",意味着 Controller 类只有没有预先构建的视图......一直到MVC 5 Controller with read/write actions and views, using Entity Framework",它产生一个具有多个方法和关联 View 的 Controller 类.cshtml 文件.
??? can be "Empty" meaning Controller class only with no pre-built views... all the way to "MVC 5 Controller with read/write actions and views, using Entity Framework" which produces a Controller class with multiple methods and associated View .cshtml files.
在 Visual Studio + MVC 的早期版本中,添加控制器"启动了一个可配置的脚手架向导.2013 的预览版本改为显示预构建的脚手架模板列表.
In prior versions of Visual Studio + MVC, "Add Controller" initiated a configurable scaffold wizard. The preview versions of 2013 instead displays a list of pre-built scaffolding templates.