Core开发-MVC 使用dotnet 命令创建Controller和View
NET Core开发-MVC 使用dotnet 命令创建Controller和View
使用dotnet 命令在ASP.NET Core MVC 中创建Controller和View,之前讲解过使用yo 来创建Controller和View。
下面来了解dotnet 命令来创建Controller和View,功能更加强大,更加完整。
结合VS Code 使你能跨平台更好更快速的开发 ASP.NET Core MVC。
也就可以在 Linux 和Mac 中更好的开发ASP.NET Core 应用程序。
创建ASP.NET Core应用程序
dotnet new -t web dotnet restore dotnet run
创建好以后,我们来添加 Controller和View。
创建使用的dotnet命令为: dotnet aspnet-codegenerator
创建Controller
1.空白Controller
dotnet aspnet-codegenerator controller -name LineZero -outDir Controllers
2.增删查改Controller
dotnet aspnet-codegenerator controller -name LineZero -actions -outDir Controllers
命令增加一个:-actions
3.增删查改+EF Controller
生成增删查改的action 及对应的视图。
dotnet aspnet-codegenerator controller -name LineZeroController -m ApplicationUser -dc ApplicationDbContext -outDir Controllers
-m 指的是model
-dc 指 DbContext
4.API Controller
dotnet aspnet-codegenerator controller -name LineZeroController -m ApplicationUser -dc ApplicationDbContext -api -outDir Controllers
增加一个 -api 就代表是生成api controller
更多命令可以参考帮助:dotnet aspnet-codegenerator controller -?
创建View
1.创建View
可以指定什么操作,Create|Edit|Delete|Details|List ,必须填入对应的model
dotnet aspnet-codegenerator view Index List -m ApplicationUser -f -outDir Views\LineZero
这里我们就创建了一个名为:Index 操作为:List 的View
-f 如果存在该文件则覆盖文件。dotnet aspnet-codegenerator 默认是不覆盖文件。
更多命令可以参考帮助:dotnet aspnet-codegenerator view -?
至此命令的展示也就完了。
dotnet aspnet-codegenerator 来源
那么这个命令是从哪里来的呢?dotnet 默认是没有aspnet-codegenerator
在 dependencies 节点添加如下:

"dependencies": {
...
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},

然后在 tools 节点添加如下:

"tools": {
...
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8"
]
}
},

dotnet restore
这样也就可以使用 dotnet aspnet-codegenerator 。
上面dotnet new 创建的web 项目可以使用 dotnet aspnet-codegenerator ,是由于项目默认已经给我们添加了对应的节点及引用。
如果你是在Windows 下使用 VS 2015 开发的话,你将得到更好的体验。
使用 VS 2015 打开带有dotnet aspnet-codegenerator的项目,VS 会自动扩展,新增额外添加功能。
在项目右键会发现多了添加 控制器,在Views 文件夹下右键,会多一个 添加 视图。
选择以后就可以添加不同类型的Controller,这个其实也是调用dotnet aspnet-codegenerator 命令。
Core开发-MVC 使用dotnet 命令创建Controller和View的更多相关文章
- ASP.NET Core开发-MVC 使用dotnet 命令创建Controller和View
使用dotnet 命令在ASP.NET Core MVC 中创建Controller和View,之前讲解过使用yo 来创建Controller和View. 下面来了解dotnet 命令来创建Contr ...
- 创建ASP.NET Core MVC应用程序(1)-添加Controller和View
创建ASP.NET Core MVC应用程序(1)-添加Controller和View 参考文档:Getting started with ASP.NET Core MVC and Visual St ...
- VisualStudioCode中用dotnet命令创建多个ASP.NET Core 项目、类库、控制台程序,并添加应用间的引用
一.准备工作 首先安装VisualStudioCode并且可以使用. 1.首先新创建空的MyApps文件夹,作为项目主目录,下面将在这个文件夹中创建多个web应用程序.类型.控制台程序等. 2.打开V ...
- MVC 用基架创建Controller,通过数据库初始化器生成并播种数据库
1 创建MVC应用程序 2 在Model里面创建实体类 using System; using System.Collections.Generic; using System.Linq; using ...
- mvc源码解读(20)-controller和view之查找view
很多时候在mvc项目中我们需要去扩展自己的视图引擎,大概看起来应该下面这个样子的: public class RazorEngineExpand : RazorViewEngine { private ...
- .NET Core dotnet 命令大全
dotnet 命令大全,让你理解dotnet 命令. 本文将以一个实例串起 dotnet 所有命令,让你玩转dotnet 命令. 本篇文章编写环境为windows 10 ,dotnet 命令同样适用于 ...
- Core dotnet 命令大全
Core dotnet 命令大全 dotnet 命令大全,让你理解dotnet 命令. 本文将以一个实例串起 dotnet 所有命令,让你玩转dotnet 命令. 本篇文章编写环境为windows 1 ...
- [转].NET Core dotnet 命令大全
本文转自:http://www.cnblogs.com/linezero/p/dotnet.html https://docs.microsoft.com/en-us/dotnet/articles/ ...
- windows/Linux下设置ASP.Net Core开发环境并部署应用
10分钟学会在windows/Linux下设置ASP.Net Core开发环境并部署应用 创建和开发ASP.NET Core应用可以有二种方式:最简单的方式是通过Visual Studio 2017 ...
随机推荐
- Vijos 1120 花生采摘
和“过河”一样,在很久以前我也曾经尝试过做这道题,可无奈当时没有看清题目.题目上说要先找最大的,然后次之.当时纠结了好久,可惜没做出来.但是现在就很好做了,只需要用结构体把每一个花生植株记录下来,so ...
- Oracle中字段的修改操作语法
对字段操作 操作方法 更新字段名 alter table TABLE_NAME rename column column_old to column_new; 添加字段 alter table T ...
- Drawable类及XMLDrawable的使用
一.性质 可直接使用.png..jpg..gif.9.png等图片作为资源,也可使用多种XML文件作为资源.(就是这些资源都能生成Drawable对象).并对XML文件作出相关处理 二.XMLDraw ...
- thinkPHP中服务器端的验证
<?php class UserModel extends Model{ //user是表的名称 必须以表名开始,继承Model类 protected $_validate=array( //a ...
- LPC基础教程-Lpc程序和编程环境 mudos 加载原理
编程环境 通常我们所见到的Mud大多是LpMud.LpMuds使用Unix的指令和文件结构.如果你对Unix有所了解,那么LpMud中的一些指令和它的文件结构与普通的Unix基本一样.如果你从未使用过 ...
- vs2005 测试 lua环境
(1)添加文件核路径 (2)库文件路径 (3)main.cpp #include <stdio.h>#include <string.h> extern "C&quo ...
- MySQLdb-python的安装
第一步下载: 第一步:进入https://github.com/farcepest/MySQLdb1/ 第二步:解压 Shell>unzip /root/MySQLdb1-MySQLdb-1.3 ...
- struts2的对象工厂(ObjectFactory)
ObjectFactory,是xwork中很重要的一个类,是产生action的地方.单独使用xwork的时候,action都是这个类创建的.struts2包装了ObjectFactory,自成了一个S ...
- PSAM SAM
第一个问题: 为什么要用SAM? 究竟谁最开始使用SAM这个词,已经无从考证,能够确认的是:这个世界上先有了PSAM,然后才有了SAM.由于网络状况的原因,或者是应用环境的要求,使用IC卡作为支付介质 ...
- POJ 1759 Garland(二分答案)
[题目链接] http://poj.org/problem?id=1759 [题目大意] 有n个数字H,H[i]=(H[i-1]+H[i+1])/2-1,已知H[1],求最大H[n], 使得所有的H均 ...