. Net Core V1.0 Creating an MVC Project
There are two ways of creating an MVC project:
I. Create a Web project: (There are too many useless things to delete too much trouble)
2. Project directory structure:
It is important to note that many JSON files are created, and the following is a brief introduction:
launchsettings.json//boot configuration file;
Appsettings.json//configuration files, such as webconfig files under the framework;
Bower.json//Storage file references, such as: jquery and other files;
Bundleconfig.json//Automatic compression can be associated with files;
Two. Create an empty Web project: (Simple and clear)
1. Create a. NET Core Web project:
2. Select an empty project:
2. After creation, the project directory structure is as follows:
3. Create the MVC folder manually:
Controller folder: Controllers
View folder: Views
Entity folder: Models (need to create, vice versa)
After creation, the project directory diagram is as follows:
4. Create controller: ( note the auto-generated ScaffoldingReadMe.txt file, this file is the hint how to configure MVC )
5. Next is the configuration, the emphasis;
My next configuration is to refer to the ScaffoldingReadMe.txt configuration steps;
Configure this node in the project file:
<ItemGroup>
<dotnetclitoolreference include= "Microsoft.VisualStudio.Web.CodeGeneration.Tools" version= "1.0.1"/>
</ItemGroup>
Remember to save OH
6. Configure the Startup.cs file: (if there are duplicates or can be deleted, or modified can be)
The first step:
//Add a constructor: PublicIconfigurationroot Configuration {Get; } PublicStartup (ihostingenvironment env) {varBuilder =NewConfigurationbuilder (). Setbasepath (env. Contentrootpath). Addjsonfile ("Appsettings.json", Optional:true, Reloadonchange:true) . Addjsonfile ($"appsettings. {env. Environmentname}.json", Optional:true) . Addenvironmentvariables (); Configuration=Builder. Build (); }
Step Two:
// Add MVC Services: Public void configureservices (iservicecollection services) { // ADD Framework services. Services. Addmvc (); }
Step Three:
//Configure web App to use the Configuration and use MVC routing: Public voidConfigure (Iapplicationbuilder app, Ihostingenvironment env, iloggerfactory loggerfactory) {Loggerf Actory. Addconsole (Configuration.getsection ("Logging")); Loggerfactory.adddebug (); if(env. Isdevelopment ()) {app. Usedeveloperexceptionpage (); } Else{app. Useexceptionhandler ("/home/error"); } app. Usestaticfiles (); App. USEMVC (Routes={routes. MapRoute (Name:"default", Template:"{controller=home}/{action=index}/{id?}"); }); }
7. Since the first time the controller was created, it was not created, only the file that configured MVC was generated, then the real controller was created:
Next, just like creating MVC under the NET Framework;
If the configuration is still uncertain, then create a non-empty MVC project, and then delete the unwanted;
. NET core. NET core V1.0 creating an MVC Project