Customer Service 1-800-221-5528

Murach’s ASP.NET Core MVC (2nd Edition)

by Joel Murach and Mary Delamater
18 chapters, 788 pages, 343 figures
Published November 2022
ISBN 978-1-943873-02-9
List price: $59.50

This book is the ideal way to teach your students how to develop ASP.NET Core MVC web apps. As usual, we present all the pieces in a logical way that helps your students see the big picture even as they’re focusing on the coding details. The only prerequisites are skills comparable to those presented in the first 8 chapters of Murach’s HTML and CSS and the first 3 sections of Murach’s C#.

Now available as a Canvas course!

The Canvas course file contains all the objectives, quizzes, assignments, and slides that you need to run an effective course. It only takes a few clicks to import it into the Canvas LMS. Then, you can customize it for your course. Learn more.

I have been very pleased with the MVC book. My students and I have learned a great deal, and I have recommended it to some other instructors from other colleges.”

Andy Bangsberg, IT Web & Software Development Instructor
Wisconsin Indianhead Technical College

  • About this Book
  • Table of Contents
  • Courseware
  • FAQs
  • Corrections

Book description

Section 1: Get off to a fast start

To give your students a solid foundation as quickly as possible, this 5-chapter section shows how to use Visual Studio to design, code, and test multi-page ASP.NET Core apps that use the MVC pattern to structure the code, EF Core to work with a database, and Bootstrap to make the apps look great on all screen sizes. After that, your students will be ready to review and expand upon what they’ve learned in this section so they can raise their skills to a professional level.

Section 2: Master the essential skills

This 8-chapter section covers the ASP.NET Core MVC skills that web developers use every day.

  • Use endpoint routing to provide user-friendly URLs that can improve SEO
  • Use Razor views and layouts to display the user interface
  • Transfer data between controllers and views
  • Use sessions and cookies to maintain state
  • Use model binding to simplify your code
  • Validate data on the client and the server
  • Use EF Core to work with a database using Code First or Database First development

The final chapter in this section presents an extensive, real-world website. Having your students study this website is a great way for them to gain a deep understanding of how all their new skills work together in a realistic ASP.NET Core MVC app.

Section 3: Add more skills as you need them

This 5-chapter section covers advanced skills that take your students to the next level. Here, they’ll learn how to:

  • Use dependency injection (DI) to make code more flexible and easier to test
  • Use xUnit and Moq to automate the testing of a web app
  • Use tag helpers, partial views, and view components to reduce code duplication in views
  • Use authorization to restrict access to parts of a web app
  • Use ASP.NET Core Identity to allow users with the appropriate privileges to access the restricted parts of a web app
  • Deploy a web app to the cloud
  • Use the Visual Studio Code text editor, an increasingly popular alternative to the Visual Studio IDE

If you don’t have time for all of these chapters (or any of them), that’s OK because sections 1 and 2 are a great course by themselves. In that case, your students can refer to the chapters in section 3 on their own to learn new skills as they need them.

What software your students need

To get the most from this book, your students need to install Visual Studio with the “.NET Core” workload as described in appendix A (Windows) or B (macOS).

On Windows, this installs all the software needed, including:

  • Visual Studio
  • .NET Core 6
  • support for C# 10.0
  • a web server called Kestrel
  • a database server called SQL Server Express LocalDB

On macOS, this workload doesn’t include SQL Server Express LocalDB, but that’s OK because your students can use SQLite instead as described in appendix B.

The prerequisites

The first prerequisite is that your students know the basics of HTML/CSS. If you use Murach’s HTML and CSS in your introductory HTML/CSS course, the first 8 chapters provide the skills they need.

The second prerequisite is that your students know the basics of C#. If you use Murach’s C# in your introductory C# course, the first 3 sections provide the skills they need.

If you don’t use Murach’s HTML and CSS or Murach’s C# for your introductory courses, we encourage you to include these books on your supplemental reading list. They make ideal references if your students come across HTML/CSS or C# code that they don’t understand.

What's new in this edition

This edition includes a new chapter that shows how to deploy a web app to the cloud. In addition, the entire book has been thoroughly updated to integrate new features and best practices from C# 10, .NET 6, ASP.NET Core MVC 6.0, Bootstrap 5.0, EF Core 6.0, and Visual Studio 2022. For a more detailed description of what’s new, please view the PDF summary.

What people said about the previous edition

“For years I had been looking for a book to teach a one-semester Microsoft ASP.NET MVC course. The publisher worked directly with me to get the instructor materials and an electronic version so I could have it ready before the semester started. Overall, I was very pleased with the book and will use it for years to come.”
 - Posted at an online bookseller

“Your launch of the ASP.NET Core MVC text is a much-needed contribution to the topic of ASP.NET Core, as well as server-side web development in general. A well-articulated and effective progression into the topic.”
 - K.S., College Instructor, Chicago, Illinois

“I have been very pleased with the MVC book. My students and I have learned a great deal, and I have recommended it to some other instructors from other colleges.”
 - Andy Bangsberg, IT Web & Software Developer
 - Instructor, Wisconsin Indianhead Technical College

“Not only is this a great book on ASP.NET Core MVC, but it’s the best programming book I’ve read on any subject. I love the format with the paired pages. The code is error-free and the numerous example applications are helpful to study. The explanations are clear and avoid some of the overly complicated word salads other books like to give.”
 - Posted at an online bookseller

“I normally don’t write in or leave reviews on products, but I felt compelled to do so with this book as it’s the first one I went through that was actually fun from start to finish (and I’ve read many, many programming books before).”
 - Shannon Fairchild, Senior Software Developer, Ontario, Canada

“I have been programming in ASP.NET Webforms and MVC for over 15 years and this book is hands-down the best programming book I’ve ever purchased.”
 - Posted at an online bookseller

“This book is a solid introduction to ASP.NET Core and can really help a beginner get up to speed in this framework. You can get a lot out of doing the exercises.”
 - Posted at an online bookseller

“At last, a dot net MVC book that explains everything clearly!”
 - Posted at an online bookseller

 

View the table of contents for this book in a PDF: Table of Contents (PDF)

Click on any chapter title to display or hide its content.

Section 1  Get off to a fast start

Chapter 1  An introduction to web programming and ASP.NET Core MVC

An introduction to web apps

The components of a web app

How static web pages are processed

How dynamic web pages are processed

An introduction to the MVC pattern

An introduction to ASP.NET Core MVC

Four ASP.NET programming models for web apps

Some web components of .NET Framework and .NET Core

An introduction to ASP.NET Core middleware

How state works in a web app

Tools for working with ASP.NET Core MVC apps

An introduction to Visual Studio

An introduction to Visual Studio Code

How an ASP.NET Core MVC app works

How coding by convention works

How a controller passes a model to a view

How a view uses Razor code, tag helpers, and Bootstrap CSS classes

How the Program.cs file configures the middleware for an app

Chapter 2  How to develop a one-page MVC web app

How to create a Core MVC web app

How to start a new web app

How to configure a web app

How to set up the MVC folders

How to add a controller

How to add a Razor view

How to configure the middleware for an HTTP request pipeline

How to run a web app and fix errors

How to run a web app

How to find and fix errors

How to work with a model

How to add a model

How to add a Razor view imports page

How to code a strongly-typed view

How to handle GET and POST requests

The Future Value app after handling GET and POST requests

How to organize the files for a view

How to add a CSS style sheet

How to add a Razor layout and view start

The code for a Razor layout and view start

How to add a Razor view when using a layout with a view start

How to validate user input

How to set data validation rules in the model

The model class with data validation

How to check the data validation

How to display validation error messages

The Future Value app after validating data

Chapter 3  How to make a web app responsive with Bootstrap

An introduction to responsive web design

A responsive user interface

How to add client-side libraries such as Bootstrap and jQuery

How to manage client-side libraries with LibMan

How to enable client-side libraries

How to get started with Bootstrap

The classes of the Bootstrap grid system

How the Bootstrap grid system works

How to work with forms

How to work with buttons and images

How to work with margins and padding

The code for the view of the Future Value app

More skills for Bootstrap CSS classes

How to format HTML tables

How to align and capitalize text

How to provide context

More skills for Bootstrap components

How to work with button groups

How to work with icons and badges

How to work with button dropdowns

How to work with list groups

How to work with alerts and breadcrumbs

How to work with navigation bars

How to create navs

How to create navbars

How to position navbars

Chapter 4  How to develop a data-driven MVC web app

An introduction to the Movie List app

The pages of the app

The folders and files of the app

How to use EF Core

How to add EF Core to your project

How to create a DbContext class

How to seed initial data

How to add a connection string

How to enable dependency injection

How to use migrations to create the database

How to work with data

How to select data

How to insert, update, and delete data

How to view the generated SQL statements

The Movie List app

The Home controller

The Home/Index view

The Movie controller

The Movie/Edit view

The Movie/Delete view

How to work with related data

How to relate one entity to another

How to update the DbContext class and the seed data

How to use migrations to update the database

How to select related data and display it on the Movie List page

How to display related data on the Add and Edit Movie pages

How to make user-friendly URLs

How to make URLs lowercase with a trailing slash

How to add a slug

Chapter 5  How to manually test and debug an ASP.NET Core web app

How to test an ASP.NET Core web app

How to run a web app

How to use the Hot Reload feature

How to use the browser’s developer tools

How to use the Internal Server Error page

How to use the Exception Helper

How to use the debugger

How to use breakpoints

How to work in break mode

How to monitor variables and expressions

How to use tracepoints

Section 2  Master the essential skills

Chapter 6  How to work with controllers and routing

How to use the default route

How to configure the default route

How the default route works

How to code a simple controller and its actions

How to code a controller that uses the id segment

How to create custom routes

How to include static content in a route

How to work with multiple routing patterns

How to use attribute routing

How to change the routing for an action

More skills for changing the routing for an action

How to change the routing for a controller

Best practices for creating URLs

How to work with areas

How to set up areas

How to associate controllers with areas

Chapter 7  How to work with Razor views

How to use Razor syntax

How to work with code blocks and inline expressions

How to code inline loops

How to code inline conditional statements

Essential skills for Razor views

The starting folders and files for an app

How to code controllers that return views

How to create a default layout and enable tag helpers

How to use tag helpers to generate URLs for links

Three views that use the default layout and tag helpers

The three views displayed in a browser

More skills for Razor views

More tag helpers for generating URLs for links

How to format numbers in a view

How to work with a model

How to pass a model to a view

How to display model properties in a view

How to bind model properties to HTML elements

How to bind a list of items to a element

How to display a list of model objects

How to work with Razor layouts

How to create and apply a layout

How to nest layouts

How to use view context

How to use sections

The Guitar Shop website

The user interface for customers

The user interface for administrators

Chapter 8  How to transfer data from controllers

How to use ActionResult objects

An introduction to ActionResult subtypes

How to return ActionResult objects

How to use the ViewData and ViewBag properties

How to use the ViewData property

How to use the ViewBag property

The NFL Teams 1.0 app

The user interface

The model layer

The Home controller

The layout

The Home/Index view

How to work with view models

How to create a view model

The updated Index() action method

The updated Home/Index view

How to redirect a request

How to use the ActionResult classes for redirection

How to use the Post-Redirect-Get pattern

How to use the TempData property

How to get started with TempData

How to use methods of the TempData dictionary

The NFL Teams 2.0 app

The user interface

The Home/Index view

The Details() action method of the Home controller

The Home/Details view

The Add() action method of the Favorites controller

The layout view

Chapter 9  How to work with session state and cookies

How ASP.NET MVC handles state

Six ways to maintain state

An introduction to session state

How to work with session state

How to configure an app to use session state

How to work with session state items in a controller

How to get session state values in a view

How to use JSON to store objects in session state

How to encapsulate session values

How to extend the ISession interface

How to use a wrapper class

The NFL Teams 3.0 app

The user interface

The session classes

The view model

The Home controller

The layout

The Home/Details view

The Favorites controller

The Favorites/Index view

How to work with cookies

How to work with session cookies

How to work with persistent cookies

The NFL Teams 4.0 app

The cookies class

The Home controller

The Favorites controller

Chapter 10  How to work with model binding

An introduction to MVC model binding

How to use controller properties to retrieve GET and POST data

How to use model binding to retrieve GET and POST data

How to use model binding with complex types

How to use model binding with nested complex types

More skills for binding data

How to use a submit button to post a value

How to post an array to an action method

How to control the source of bound values

How to control which values are bound

The ToDo List app

The user interface

The entity classes

The database context class

A utility class for filtering

The Home controller

The layout

The Home/Index view

The Home/Add view

Chapter 11  How to validate data

How data validation works in MVC

The default data validation provided by model binding

How to use data attributes for validation

A Registration page with data validation

How to control the user experience

How to format validation messages with CSS

How to check validation state and use code to set validation messages

How to display model-level and property-level validation messages

How to enable client-side validation

How to customize server-side validation

How to create a custom data attribute

How to pass values to a custom data attribute

How to check multiple properties

How to customize client-side validation

How to add data attributes to the generated HTML

How to add a validation method to the jQuery validation library

How to work with remote validation

The Registration app

The user interface and CSS

The Customer and RegistrationContext classes

The MinimumAgeAttribute class

The minimum-age JavaScript file

The Validation and Register controllers

The layout

The Register/Index view

Chapter 12  How to use EF Core

How to create a database from code

How to code entity and DB context classes

How to configure the database

How to manage configuration files

EF commands for working with a database

How to use EF migration commands

How to work with relationships

How entities are related

How to configure a one-to-many relationship

How to configure a one-to-one relationship

How to configure a many-to-many relationship

How to seed data in the linking table of a many-to-many relationship

How to control delete behavior

The Bookstore database classes

The entity classes

The context and configuration classes

How to create code from a database

How to generate DB context and entity classes

How to configure a generated DB context class

How to modify a generated entity class

How to work with data in a database

How to query data

How to work with projections and related entities

How to insert, update, and delete data

How to handle concurrency conflicts

How to check for concurrency conflicts

How handle a concurrency exception

How to encapsulate your EF code

How to code a data access class

How to use a generic query options class

How to use the repository pattern

Chapter 13  The Bookstore website

The user interface and folder structure

The end user pages

The admin user pages

The folders and files

Some general-purpose code

Extension methods for strings

The generic QueryOptions class

The generic Repository class

The paging and sorting of the Author Catalog

The user interface and custom route

The abstract GridData class

The AuthorGridData subclass

The Author/List view model and the Author controller

The Author/List view

The paging and sorting of the Book Catalog

The user interface and custom route

The BookGridData subclass

The Book/List view model and the Book controller

The Book/List view

The Cart page

Extension methods for session and cookies

The user interface

The model classes

The Cart controller

The Cart/Index view

The Admin area

The BookRepository subclass

The Related Books page

The Delete() and Related() action methods

Section 3  Add more skills as you need them

Chapter 14  How to use dependency injection and unit testing

How to use dependency injection (DI)

How to configure your app for DI

How to use DI with controllers

How to create an interface for an existing class

How to use DI with an HttpContextAccessor object

How to use DI with action methods

How to use DI with views

How to get started with unit testing

How unit tests work

How to add an xUnit project to a solution

How to write a unit test

How to run a unit test

How to test methods that have dependencies

How to use a fake repository object

How to use a fake TempData object

How to create fake objects with Moq

How to work with mock objects

How to mock a repository object

How to mock a TempData object

How to mock an HttpContextAccessor object

The Bookstore.Tests project

The Test Explorer

The Usings.cs file

The BookControllerTests class

The AdminBookControllerTests class

The CartTests class

Chapter 15  How to work with tag helpers, partial views, and view components

An introduction to tag helpers

How to use tag helpers

How to register tag helpers

How to create custom tag helpers

How to create a custom tag helper

How to create a tag helper for a non-standard HTML element

How to use extension methods with tag helpers

How to control the scope of a tag helper

How to use a tag helper to add elements

More skills for custom tag helpers

How to use properties with a tag helper

How to work with the model property that an element is bound to

How to use a ViewContext object with a tag helper

How to use dependency injection with a tag helper

How to create a conditional tag helper

How to generate URLs in a tag helper

How to work with partial views

How to create and use a partial view

How to pass data to a partial view

How to work with view components

How to create and use a view component

How to pass data to a view component

The Bookstore app

The Book Catalog page

The updated ActiveNavbar tag helper

The layout

The Book/List view

Chapter 16  How to authenticate and authorize users

An introduction to authentication

Three types of authentication

How individual user account authentication works

An introduction to ASP.NET Identity

How to restrict access to controllers and actions

How to get started with Identity

How to add Identity classes to the DB context

How to add Identity tables to the database

How to configure the middleware for Identity

How to add Log In/Out buttons and links to the layout

How to start the Account controller

How to register a user

The Register view model

The Account/Register view

The Register() action method for POST requests

The LogOut() action method for POST requests

How to log in a user

The Login view model

The Account/Login view

The LogIn() action method for POST requests

How to work with roles

Properties and methods for working with roles

The User entity and view model

The User controller and its Index() action method

The User/Index view

Other action methods of the User controller

The code that restricts access

How to seed roles and users

More skills for working with Identity

How to change a user’s password

How to add more user registration fields

Chapter 17  How to deploy ASP.NET Core MVC apps

How to work with Visual Studio’s publish feature

How work with publish profiles

How to work with the Publish wizard

How to publish to the file system

How to create a publish profile for the file system

How to deploy to a publish folder

How to change the publish folder

How to publish a simple app to Azure

How to get started with Azure

How to create a publish profile for an Azure App Service

How to deploy to the Azure App Service

How to publish a data-driven app to Azure

How to add an Azure SQL Database to a publish profile

How to configure a connection string and migrations in a publish profile

How to deploy a data-driven app to the Azure App Service

How to work with an Azure app

An introduction to the Azure portal

How to delete an Azure App Service

Chapter 18  How to use Visual Studio Code

How to work with existing projects

How to install VS Code

How to open and close a project folder

How to view and edit files

How to run and stop a project

How to create the database for a project

A summary of .NET EF Core commands

How to start a new project

How to create a new project

How to add NuGet packages to a project

How to work with the folders and files

How to install and manage client-side libraries

How to debug a project

How to set a breakpoint

How to work in break mode

Appendixes

Appendix A  How to set up Windows for this book

How to install Visual Studio

How to install the source code for this book

How to create the databases for this book

Appendix B  How to set up macOS for this book

How to install Visual Studio

How to install the source code for this book

Problems and solutions when using macOS with this book

How to install and use DB Browser for SQLite

If you haven’t ever seen the supporting courseware that we provide for a book, please go to About our Courseware.

End-of-chapter activities in the book

  • Terms list
  • Summary bullets
  • Step-by-step exercises

Student download at our retail site

  • Source code for the apps presented throughout the book
  • Starting code for the exercises presented at the end of each chapter
  • Solutions to the exercises

Appendixes A (Windows) and B (macOS) give your students complete instructions for downloading and installing these items on their own computers.

Instructor’s materials

  • Instructional objectives by chapter
  • Accessible PowerPoint slides
  • Test banks in multiple formats
  • Student projects that can be assigned at the end of each chapter, plus solutions for each project
  • A case study where the students build a complete app as they progress through the book, plus solutions for the app as it should be at the end of each section
  • The source code that students can download at our retail site including (1) the book apps, (2) starting points for the exercises in the book, and (3) solutions to the book exercises

For a more detailed description of the courseware for this book, please read the Instructor’s Summary.

On this page, we’ll be posting answers to the questions that come up most often about this book. So if you have any questions that you haven’t found answered here at our site, please email us. Thanks!

There are no book corrections that we know of at this time. But if you find any, please email us, and we’ll post any corrections that affect the technical accuracy of the book here. Thank you!

Murach college books and courseware since 1974