在 Visual Studio 2013/ASP.NET MVC 5 中,如何添加新控制器? [英] In Visual Studio 2013 / ASP.NET MVC 5, How do I add a new Controller?

查看:26
本文介绍了在 Visual Studio 2013/ASP.NET MVC 5 中,如何添加新控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ASP.NET MVC5 + VS 2013(撰写本文时的预览版)中,如何添加新控制器?

In ASP.NET MVC5 + VS 2013 (preview at time of writing), how do I add a new Controller?

在过去的版本 (VS 2012/MVC 4) 中,我可以右键单击 Controllers 文件夹,然后单击添加控制器".该选项不再存在.去哪儿了?

In past versions (VS 2012 / MVC 4), I was able to right click on the Controllers folder and click "Add Controller". That option is no longer there. Where did it go?

(旁注:我不确定 MVC 5 是否是发生变化的地方,或者它是否是 VS 2013 工具中的变化,因为我更新了两者.我怀疑是 VS 2013 的新 ASP.NET 工具)

(Side note: I am not certain if MVC 5 is where the change takes place or if it a change in the VS 2013 tooling as I updated both. I suspect it is with the new ASP.NET tooling for VS 2013)

推荐答案

在 2013 年 11 月 14 日更新了这个答案,在 VS2013 正式发布之后,以反映最终版本中的变化 -ds

对于 Visual Studio 2013(发布版)

注意:最终版本带回了添加控制器"上下文菜单.

简单的方法:

  1. 右键单击 MVC 项目中的Controllers"文件夹

  1. Right Click on the "Controllers" folder in your MVC project

添加 > 控制器...

选择一个控制器模板.(我更喜欢 MVC 5 Controller Empty)

Choose a Controller Template. (I prefer MVC 5 Controller Empty)

替代方式:

  1. 右键单击 MVC 项目中的Controllers"文件夹

  1. 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:

  1. 右键单击 Controllers 文件夹.
  2. 点击添加 > 脚手架...
  3. 选择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.

这篇关于在 Visual Studio 2013/ASP.NET MVC 5 中,如何添加新控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆