asp.net core mvc 项目搭建一、【3分钟学会】

asp.net core作为VS开发下一步的主要框架,主要应对分布式,大数据等方向设计的未来框架 。有部分不足但是发展大于现有。所以可以从熟悉的项目入手开始试用asp.net core框架。一个简单能用的实例,不仅可以增加你的学习信心,更能开拓你的编程架构思路。

一、新建.net core mvc项目

从vs2019中新建项目 选asp.net core web

项目名称 自己取

选择Web应用程序 mvc版本

新建.net core mvc项目

常用的6个文件位置,都已经标注到下面了。从上到下分别是

1 网站使用的vss和js以及部分静态页面也可以放到这里。 

2.Controller控制器的文件夹。 熟悉MVC的人对这个都是比较熟悉了。 

3. Model 实体类,最好和数据库 视图、表、存储过程等一一对应。方便你后续的使用

4.View 视图文件夹,试图页面都在此文件夹中。 

*当然你也可以 用Areas的方式分类。 

5. 这个json文件中主要是配置方面的信息。可以从后续的代码中学到用法。 

6.启动文件,从名字就可以看出这就是项目启动后的入口。 当然里面也包含很多预设的启动类

这些文件或者文件夹都是比较重要的。 启动文件是startup 是启动文件,appsetting.json里面可以存放链接字符串。

外部的无限多可以用的包,可以用(官方还提示了有多少人使用过)。对于小白来说可以大大减少选择的时间。 

初期还是用常用的包稳定,可靠。 后续你也可以自己写写包发布上去。 

开始增加EF的包

这三个就是管理外置包的地方,第一个是控制台添加。 第二个是窗口版本的添加。效果一样。

Microsoft.EntityFrameworkCore.SqlServer

Microsoft.EntityFrameworkCore.Tools

Microsoft.EntityFrameworkCore.SqlServer.Design

依次添加 这样的三个包

创建实体类Models

数据库、表的创建 参考sqlserver 的数据库教程

这步就不介绍了。 

建好表之后,在上面的5的最后一个菜单 第一个选项 控制台中执行下面的句子

Scaffold-DbContext "Server=192.168.1.100;Database=VideoSms;UID=sa;PWD=123456" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force -UseDatabaseNames

在黑窗口中显示

表示导入成功。 在Models的文件夹中就出现了你需要的文件。

注意 避坑:再次执行上面的命令报错的时候。 把项目重新编译一次就好了。 至此。你的环境已经搭建完毕。 剩下的和普通的mvc开发就没什么区别了。

二、让你的项目好看点 (未完待续)

"Learning ASP.NET Core MVC Programming" English | ISBN: 1786463830 | 2016 | EPUB | 342 pages | 17 MB Key Features Get a first-principles coverage of ASP.NET MVC and the latest release, Core This book is uniquely designed for developers who are looking to transition their skills into the .NET development field The standalone chapter structure leaves you free to explore ASP.NET MVC to immediately solve your pain points Book Description ASP.NET Core MVC helps you build robust web applications using the Model-View-Controller design. This guide will help you in building applications which can be deployed on non-windows platforms such as Linux. In today's age, it is crucial that you possess the ability to separate the programming and business logic, and this is exactly what ASP.NET Core MVC application will help you achieve. This version comes with a number of improvements that enable fast, TDD-friendly development to create sophisticated applications. You would also learn the fundamentals of Entity framework and on how to use the same in ASP.NET Core web applications. The book presents the fundamentals and philosophies of ASP.NET Core. Starting with an overview of the MVC pattern, we quickly dive into the aspects that you need to know to get started with ASP.NET. You will learn about the core architecture of model, view, and control. Integrating your application with Bootstrap, validating user input, interacting with databases, and deploying your application are some of the things that you will be able to execute with this fast-paced guide. The end of the book will test your knowledge as you build a fully working sample application using the skills you've learned throughout the book. What you will learn Get to know the concepts of ASP.NET MVC and build a new static web page using HTML, CSS, and jQuery Set up a development environment and run a sample application using the template Create a Controller with action methods Build a view using several features of the Razor View engine Construct a Model for ASP.NET Core MVC application Devise a custom mechanism to provide maximum flexibility to your application through routing Validate the user input on the client side using jQuery Enhance your applications using Bootstrap Explore new configuration and deployment scenarios—step by step guide to deploying ASP.NET Core web application in Linux
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值