Creating the ASP.NET MVC project

To create a new ASP.NET MVC project, perform the following steps:

  1. In Visual Studio, create a new ASP.NET Core Web Application project, as shown in the following screenshot:
    Creating the ASP.NET MVC project
  2. In the New ASP.NET Core Web Application dialog, select the Empty template under the ASP.NET Core Templates and click on the OK button:
    Creating the ASP.NET MVC project
  3. Visual Studio will create a default empty MVC project. Right-click on the wwwroot folder inside the project and navigate to Add | New Folder. Create the following two folders:
    • css 
    • js
  4. Add the styles.css file from the Bootstrap 4 Admin Dashboard template css folder to the css folder inside the wwwroot folder in the project.
  5. Copy the scripts.js file located in the Bootstrap 4 Admin Dashboard template's js folder to the js folder in the project's wwwroot folder.
  6. Next, add two folders to the root of the project called Controllers and Views.
  7. Next, in order to enable MVC features such as tooling and Tag Helpers, open the project.json file and add the following to the list of dependencies and tools:
            "dependencies": {
             "Microsoft.NETCore.App": {
             "version": "1.0.0",
             "type": "platform"
             },
             "Microsoft.AspNetCore.Diagnostics": "1.0.0",
             "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
             "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
             "Microsoft.Extensions.Logging.Console": "1.0.0",
             "Microsoft.AspNetCore.Mvc": "1.0.0",
             "Microsoft.AspNetCore.StaticFiles": "1.0.0",
             "Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
             "Microsoft.AspNetCore.Razor.Tools": {
             "version": "1.0.0-preview2-final",
             "type": "build"
             },
             "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": {
             "Microsoft.AspNetCore.Server.IISIntegration.Tools":
             "1.0.0-preview2-final",
             "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
             "version": "1.0.0-preview2-final",
             "imports": [
             "portable-net45+win8"
             ]
             }}
  8. When you save the project.json files, Visual Studio will automatically add all the required dependencies to the project.
  9. Open the Startup.cs file in the project root and change the ConfigureService method to enable MVC, as illustrated here:
            public void ConfigureServices(IServiceCollection services) 
            { 
                services.AddMvc(); 
            } 
    
  10. Enable static files and specify a default route by altering the Configure method, as shown in the following code:
            public void Configure(IApplicationBuilder app) 
            { 
                app.UseIISPlatformHandler(); 
                app.UseStaticFiles(); 
                app.UseMvc(routes => 
                { 
                    routes.MapRoute( 
                        name: "default", 
                        template: "{controller=Home}/{action=Index}/{id?}"); 
                }); 
            } 
    
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.30.62