Index A Action results. See Controllers Actions. See Controllers Application model, 986 action constraints, 1000 Areas. See Routing Arrow functions. See Lambda expressions ASP.NET Core MVC (see Model View Controller (MVC)) Identity (see Identity) middleware, 391 Asynchronous methods, 99 async keyword, 101 Attribute routing. See Routing Authentication. See Identity Authorization. See Identity Authorize attribute. See Identity await keyword, 101 B Bower, 133, 352 bower.json file, 376 Bundling files, 157 C C# features anonymous types, 96 asynchronous methods, 99 extension methods, 85 getting member names, 102 initializers, 80 lambda expressions, 90 null conditional operator, 73 pattern matching, 83 properties, automatically implemented, 76 string interpolation, 79 type inference, 96 Client-side validation. See Model validation Configuration. See Projects Connection strings, 211 Controllers, 507 action method parameters, 520 action results, 524 base class, 514 context data, 516 folder, 62 naming conventions, 64 POCO controllers, 512 purpose in MVC pattern, 54 responses, 522 errors, 547 files, 545 HTML, 526 HTTP codes, 547 JSON, 543 redirections, 535 View method, 527 RESTful controllers, 632 content formatting, 645 content negotiation, 647 defining routes, 636 dependencies, 636 HTTP method attributes, 637 JSON, 639 Route attribute, 636 XML, 648 temp data, 541 unit testing, 526 View method, 527 Conventions, 63 controller conventions, 64 layouts, 65 over configuration, 63 view conventions, 64 D Data model. See Model Data validation. See Model validation Adam Freeman 2017 A. Freeman, Pro ASP.NET Core MVC 2, https://doi.org/10.1007/978-1-4842-3150-0 1013
Dependency injection, 551 action injection, 581 closely coupled components, 557 concrete types, 570 dependency chains, 568 lifecycles, 573 scoped, 578 singleton, 580 transient, 574 loosely coupled components, 556 manually accessing services, 582 property injection, 582 service provider, 564 SportsStore, 202, 271 Deployment, 334 connection strings, 335 preparing Azure, 335 Domain data. See Model E Entity Framework Core connection string, 887 creating an Identity database, 323 deleting data from the database, 319 migrations, 214, 296, 340 schema changes, 284 scope validation, 213 SportsStore, 209 updating the database, 308 Extension methods, 85, 90 F Filters, 585 action filters, 597 authorization filters, 594 context data, 593 dependency injection, 610 exception filters, 607 filter types and interfaces, 592 global filters, 618 hybrid action/result filters, 605 order of execution, 620 RequireHttps attribute, 591 result filters, 601 Font Awesome, 276 Form data, 32 G Git, 351 H Hosting environment, 402 HTML Helpers. See Tag helpers I, J, K Identity, 881 authentication, 920 third-parties, using, 976 authorization, 928 Authorize attribute, 920 claims, 955 connection strings, 324 creating users, 893 custom properties, 951 database, 887 password validation, 897 policies, 955, 964 resources, 970 roles, 928 seed data, 326 SportsStore, 323 third-party authentication, 976 user account validation, 904 user class, creating, 885 UserManager class, 890 Initializers for objects and collections, 80 L Lambda expressions, 90 Language features. See C# features Layouts. See Razor, layouts Linux. See Visual Studio Code Logging, 415 Loosely coupled components. See Dependency injection M macos. See Visual Studio Code Middleware, 391 Minifying files, 157 Model, 26 conventions, 991 role in MVC pattern, 53 Model binding, 33, 811 arrays and collections, 832 complex types, 821 data sources, 839 request bodies, 845 1014
request headers, 841 default values, 818 simple types, 820 Model validation, 849 asp-validation-summary attribute, 860 checking the model state, 40 client-side validation, 874 SportsStore, 315 custom validation messages, 862 explicit validation, 855 highlighting validation errors, 43 input-validation-error attribute, 858 metadata, 869 Compare attribute, 870 custom attributes, defining, 872 Range attribute, 870 RegularExpression attribute, 870 Required attribute, 870 StringLength attribute, 870 ModelState property, 856, 866 remote validation, 877 SportsStore, 290, 310, 312 validation errors, showing, 858 using nullable types, 40 Model View Controller (MVC) action method, 17 architectural overview, 6 compared to ASP.NET Web Forms, 4 controller, 17 compared to Web Forms, 35 editing default controller class, 18 conventions, 63 creating new project, 13 extensibility, 7 history of, 3 original MVC Framework, 5 model. See Model open-source, 9 pattern ASP.NET implementation, 55 controllers, 54 models, 53 other patterns, 56 separation of concerns, 53 views, 55 projects. See Projects routing system, 8 view, 20 creating a view, 21 view engine, 23 Moq. See Unit testing MVC. See Model View Controller (MVC) N.NET Core, 5 Node.js, 349 Node Package Manager (NPM), 352 NuGet packages. See Visual Studio Null conditional operator, 73 Null values, 73 O OS X. See Visual Studio Code P, Q Partial views SportsStore, 235 Pattern matching, 83 Post/Redirect/Get Pattern, 540 Projects appsettings.json file, 211 Areas folder, 62 bower.json file, 376 Components folder, 62 Controllers folder, 62 creating new project, 60 Data folder, 62 Dependencies folder, 62 Empty template, 61 hosting environment, 402 Kestrel web server, 385 logging, 415 Migrations folder, 62 Models folder, 62 MVC services, 420 Program class, 382 Program.cs file, 63 Startup class, 386 Startup.cs file, 63 _ViewImports.cshtml file, 111 Views folder, 62 Web Application (MVC) template, 61 Properties, automatically implemented, 76 R Razor, 23 conditional statements, 122 configuration, 684 in context, 105 expressions, 109 layouts, 23, 112 1015
Razor (cont.) Layout property, 112 @model expression, 36, 109, 119 model keyword, 36 @model vs. @Model, 109 @RenderBody expression, 113 strongly typed views, 110 @using expression, 112 view imports, 111 _ViewImports.cshtml file, 111 view location expanders, 685 Views/Shared folder, 118 _ViewStart.cshtml file, 116 view start file, 116 Visual Studio IntelliSense, 110 Razor View Engine. See Razor Receiving form data, 32 RESTful Controllers. See Controllers Routing, 8, 429 areas, 497 Area attribute, 499 attribute routing, 463 Route attribute, 464 best practices, 503 catchall segments, 451 constraints, 453 combining, 459 custom, 461 regular expressions, 457 types, 458 values, 458 creating links, 471 customization, 484 default values, 437 MapRoute method, 435 optional segments, 449 ordering routes, 442 outgoing URLs, 471 segment variable reuse, 478 segment variables, 445 SportsStore, 207 static segments, 440 URL patterns, 434 URL segments, 434 S Scope validation, 213 Separation of concerns. See Model View Controller (MVC), pattern Services. See Dependency injection Session data, 263 temp data, 311 SportsStore administration features, 295 Bootstrap CSS framework, 231 1016 checkout process, 280 configuration, 212 connection string, 211 controllers, 204 database context class, 210 database, creating, 208 dependency injection, 271 deployment, 334 migrations, 284 model, creating, 200 navigation, 237 pagination, 218 partial view, 235 project, creating, 194 routing, 207 session data, 263 shopping cart, 257 tag helper, 221 unit test project, creating, 198 validation, 290 views, 205 SQLite, 364 Static content, 63 String interpolation, 79 T Tag helpers, 29, 721 anchor elements, 797 application relative URLs, 806 asp-action attribute, 29, 31, 758, 797 asp-antiforgery attribute, 758 asp-append-version attribute, 784 asp-area attribute, 758, 797 asp-controller attribute, 758, 797 asp-fallback-* attributes, 784, 794 asp-for attribute, 31, 762, 768, 770, 777 asp-format attribute, 762 asp-fragment attribute, 797 asp-host attribute, 797 asp-href-exclude attribute, 794 asp-href-include attribute, 794 asp-items attribute, 770 asp-route attribute, 758, 797 asp-src-exclude attribute, 784 asp-src-include attribute, 784 asp-validation-for attribute, 864 asp-validation-summary attribute, 42, 860, 867 cache busting, 791 caching, 799 content delivery networks, 792 context data, 729 cross-site request forgery, 760 CSS files, 794 form elements, 755 hosting environment, 783
image elements, 798 input elements, 762 Javascript files, 784 label elements, 768 output, producing, 730 registration, 731 scope, 734 select and option elements, 770 shorthand elements, creating, 739 SportsStore, 221 TagHelper base class, 728 textarea elements, 777 Temp data, 311 U Unit testing, 167 controllers, 526 Fact attribute, 170 filters, 596 isolating components, 174 mocking framework, 187 project configuration, 168 running tests, 172 SportsStore, 198 tag helpers, 733 test-driven development, 180 view components, 712 Visual Studio Code, 370 URL Routing. See Routing V Validation. See Model validation View bag, 534 View bag data, 24 View components, 691 asynchronous view components, 713 context data, 707 controllers, combined with, 715 HTML results, 705 partial views, 703 POCO view components, 699 results, 702 SportsStore, 246 ViewComponent base class, 700 ViewResult class, 23 Views, 657 appsettings.json file, 63 creating HTML form, 30 csproj file, 63 JSON data, 682 layout sections, 673 @model expression, 28 naming conventions, 64 optional sections, 677 partial views, 679 purpose in MVC pattern, 55 Razor, 666 search locations, 528 selecting specific views, 687 specifying a model type, 28 strongly typed, 27 view engines, 659 view imports file, 62 Views folder, 62 view start file, 63 Visual Studio Bower, 133 bower.json file, 133 package version numbers, 135 Browser Link, 147 bundling and minification, 157 client-side packages, 133 configuring authentication, 14 debugging, 142 breakpoints, 143 data values, 146 developer exception pages, 141 IIS Express, 19 installing, 11 iterative development, 137 NuGet packages, 131 project templates file and folder structure, 16 Web Application (Model-View-Controller), 14 scaffolding, 204 selecting browser, 17 starting an application, 16 Test Explorer window, 172 Visual Studio 2015. See Visual Studio Visual Studio Code, 349 Bower, 352 C# extension, 355 creating new project, 356 Git, 351 installing, 353.NET Core, 352 Node.js, 349 Node Package Manager (NPM), 352 SQLite, 364 unit testing, 370 W Web API. See Controllers X, Y, Z xunit. See Unit testing 1017