O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning ASP.NET Core MVC Programming

Book Description

Learn the fundamentals of ASP.NET MVC and build real-world web applications using ASP.NET Core MVC

About This Book

  • 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

Who This Book Is For

This book is for developers who want to learn to build web applications using ASP.NET Core, developers who want to make a career building web applications using Microsoft technology, and developers who are working in Ruby on Rails or other web frameworks and want to learn ASP.NET Core MVC.

No knowledge of the ASP.NET platform or the .NET platform is required. Even though you do not need to have experience in C#, an understanding of the basic constructs (loops, conditionals, classes, and objects) of any modern programming language would be helpful.

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

In Detail

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.

Style and approach

This book takes a first-principles approach to help you understand and implement ASP.NET MVC solutions. It is focused primarily on giving you practical skills rather than the old conventional theoretical teaching.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Learning ASP.NET Core MVC Programming
    1. Learning ASP.NET Core MVC Programming
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. www.PacktPub.com
      1. Why subscribe?
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    7. 1. Introduction to ASP.NET Core
      1. How web applications work
        1. So what is an HTTP protocol?
          1. Request-response pattern
          2. Stateless nature of HTTP
      2. Client-side and server-side
      3. HTTP methods
        1. GET method
        2. POST method
      4. What is ASP.NET?
        1. ASP.NET Web Forms
        2. ASP.NET Web Pages
        3. ASP.NET MVC
      5. Features of ASP.NET MVC
        1. Convention over configuration
        2. Separation of concerns
        3. Control over the generated HTML
        4. Better support for unit testing
      6. ASP.NET 5
        1. Features of ASP.NET 5
      7. Summary
    8. 2. Setting Up the Environment
      1. Purpose of IDE
      2. Visual Studio offerings
        1. System requirements
          1. Visual Studio Community 2015
          2. Visual Studio Professional
          3. Visual Studio Enterprise
          4. Visual Studio Test Professional
      3. Installing Visual Studio Community
      4. Installing ASP.NET 5
      5. Project structure in ASP.NET 5 application
        1. File-based project
          1. Support for full .NET and .NET core
          2. The Project.json package
          3. Controllers
          4. Models
          5. Views
          6. Migrations
          7. The wwwroot folder
          8. Other files
      6. Summary
    9. 3. Controllers
      1. Role of the Controller in ASP.NET MVC applications
      2. Introduction to routing
      3. Creating ASP.NET 5 application
      4. Installing the ASP.NET Core NuGet package in your application
      5. Our first Controller
        1. IActionResult
      6. Adding Views
      7. Adding Models
      8. Passing data from Controller to View
      9. Filters
        1. Authorization filters
        2. Resource filters
        3. Action filters
        4. Exception filters
        5. Result filters
      10. Summary
    10. 4. Views
      1. The View engine and the Razor View engine
        1. Razor View engine
          1. Programming in Razor View engine
          2. Variables in Razor View
            1. The for loop
            2. The while loop
            3. The foreach loop
            4. The if condition
      2. Layout
        1. Creating _ViewStart.cshtml
        2. Creating _Layout.cshtml
        3. Adding a page-specific View
      3. Generating HTML
        1. HTML Helpers
      4. Partial View
        1. Calling the Partial View
      5. View components
        1. Creating a View component
      6. Tag Helpers
        1. Creating custom Tag Helpers
      7. Summary
    11. 5. Models
      1. Models
        1. Models specific to a View component
        2. Note on ViewModels
        3. Data flow with respect to a Model
      2. Model binding
      3. The Entity Framework
        1. The Entity Framework is independent of ASP.NET MVC
        2. Creating console applications with the Entity Framework
        3. Installing the Entity Framework 7 NuGet package
          1. Using the NuGet Package Manager
          2. Using the Package Manager Console
        4. Installing Entity Framework commands
          1. Creating Model classes
          2. Creating the DbContext class
        5. Create a migration
        6. How the SaveChanges method works
        7. Updating the record
        8. Deleting the record
      4. Using the Entity Framework in ASP.NET MVC applications
      5. Database migration
      6. Summary
    12. 6. Validation
      1. Client-side and server-side validation
      2. Server-side validation
        1. Updating View models with the Data Annotation attribute
        2. Updating the View model to display the validation error message
        3. Updating the controller action method to verify the model state
      3. Client-side validation
      4. Implementation
      5. Summary
    13. 7. Routing
      1. Convention-based routing
        1. Example 1
        2. Example 2
        3. Example 3
        4. Example 4
      2. Attribute-based routing
      3. Route attribute at the controller level
      4. Passing routing values in HTTP action verbs in the Controller
      5. Route Constraints
      6. Summary
    14. 8. Beautifying ASP.NET MVC Applications with Bootstrap
      1. Knowing HTML and CSS
      2. Bootstrap
        1. Bootstrap Grid system
        2. Forms
          1. Inline forms
          2. Horizontal forms
        3. Table CSS classes
          1. Striped tables
          2. Hover tables
          3. Bordered tables
          4. Contextual classes in table
        4. Buttons
          1. Button sizes
        5. Contextual colors
      3. Using Bootstrap in your ASP.NET MVC application
      4. Installing with Bower
      5. HTML doctype
      6. Summary
    15. 9. Deployment of ASP.NET Core Application
      1. The project.json file
        1. The dependencies node
        2. The frameworks node
      2. Microsoft Azure
        1. Signing up to Microsoft Azure
        2. Prerequisites to Azure deployment
      3. Deploying the ASP.NET Core application in Azure
      4. Deploying the ASP.NET Core web application in the Linux environment
        1. Creating a Linux machine
        2. Installing the PuTTY client
        3. Installing of .NET Core in a Linux machine
      5. Creating a new ASP.NET 5 project
      6. Configuring the Nginx server
      7. Summary
    16. 10. Building HTTP-based Web Services Using ASP.NET Web API
      1. HTTP basics
        1. HTTP verbs
        2. GET method
        3. PUT method
        4. POST method
        5. DELETE method
        6. Fiddler tool
      2. Dependency Injection
        1. Delete method
          1. The Web API method for deleting a resource
          2. Web Repository layer code for deleting the employee data
      3. Summary
    17. 11. Improving Performance of an ASP.NET Core Application
      1. The UI layer
      2. Reducing the number of HTTP requests
        1. Using GZip compression
        2. Using the Content Delivery Network (CDN)
        3. Using JavaScript wherever possible
        4. Using CSS stylesheets
      3. Minification of JavaScript and CSS files and their combination
      4. The caching process
        1. Client-side caching
        2. Response caching
      5. The web/application layer
        1. No business logic in Views
        2. Using asynchronous logging
        3. The DB layer
          1. Understanding the queries generated by the ORM
          2. Using classic ADO.NET if you really want to
          3. Return only the required data
          4. Fine tuning the indices
          5. Using the correct column type and size for your database columns
          6. Avoiding correlated subqueries
      6. Generic performance improvement tips
        1. Avoiding the Response.Redirect method
        2. Using string builder
      7. Summary
    18. 12. ASP.NET Core Identity
      1. Authentication
      2. Authorization
      3. Adding the relevant dependencies to the project.json file
        1. Adding ApplicationUser and ApplicationDbContext classes
      4. Configuring the application to use Identity
      5. Creating ViewModels
      6. Creating Controllers and associated action methods
      7. Creating Views
      8. E-mail and SMS services
      9. Securing an action method in a Controller
      10. Summary