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 ...
随机推荐
- UIButton 头文件常见属性和方法
UIButton头文件常见属性 1.属性 contentEdgeInsets: default is UIEdgeInsetsZero.设置内容四边距,默认边距为0 @property(nonatom ...
- 远程控制利器TeamViewer使用教程(图)
TeamViewer是什么? 他是一款免费的可以穿透内网的远程控制软件,可以实现桌面共享,文件传送等功能,简单一点说就是和QQ远程协助一样,但是比QQ的远程协助功能更为强大. TeamViewer与木 ...
- model、dao、 service 和Comtroll层的关系
首先这是现在最基本的分层方式,结合了SSH架构.modle层就是对应的数据库表的实体类.Dao层是使用了Hibernate连接数据库.操作数据库(增删改查).Service层:引用对应的Dao数据库操 ...
- bugfree搭建
- AutoItLibrary库入门
一.AutoItLibrary入门 1. 为什么要使用AutoItLibrary Selenium2library在我们实际测试web页面的时候基本上已经够用了,不过还是会有部分情况下会脱离Selen ...
- python sys.exit()函数说明
sys.exit()函数是通过抛出异常的方式来终止进程的,也就是说如果它抛出来的异常被捕捉到了的话程序就不会退出了. #!/usr/bin/python #!coding:utf-8 import s ...
- MySQLdb-python的安装
第一步下载: 第一步:进入https://github.com/farcepest/MySQLdb1/ 第二步:解压 Shell>unzip /root/MySQLdb1-MySQLdb-1.3 ...
- secedit
secedit /export /cfg mytemplate.inf /log mylog.txt http://www.oracle-base.com/dba/script.php?categor ...
- Azure 为 SAP 提供的增强监控解决方案
正如大家在之前公告中所看到的,多个SAP应用程序已获得认证可在 Azure虚拟机中运行,未来还会有更多 SAP应用程序获得认证.对于希望在 Azure中运行 SAP应用程序的客户来说,这是个激动人心的 ...
- web本地存储-WebSQL
Web SQL数据库API实际上未包含在HTML 5规范之中,它是一个独立的规范,它引入了一套使用SQL操作客户端数据库的API.W3C 官方在 2011 年 11 月声明已经不再维护 Web SQL ...