11 Client-side technologies and AJAX

 

This chapter covers

  • Choosing your client-side technology
  • Calling page handlers from client-side code
  • Working with JSON in Razor Pages
  • Isolating CSS styles on a per-page basis

All the code examples we have worked with have relied on the HTML for the page being generated in full on the server, except in one area: client-side validation. The validation error messages were generated using client-side libraries, specifically Microsoft’s jQuery Unobtrusive Validation library. As a feature, client-side validation enhances the usability of the website. It gives users instant feedback on form validation errors, without waiting for the entire form to be submitted to the server for processing.

Usability is critical if you want to keep your users happy, and usability can be improved dramatically in server-side applications using client-side technologies. In this chapter, we will look at how to implement some common patterns that use client-side technologies within a Razor Pages application. Since it is included as part of the default project template, we will look at jQuery for DOM manipulation and making asynchronous HTTP requests initiated by the browser. We will also explore alternatives, using plain JavaScript, and consider the future of jQuery.

11.1 Choosing your client-side technology

11.2 Calling page handlers from JavaScript

11.2.1 Using a partial page to return HTML

11.2.2 Posting to a page handler

11.2.3 Working with JsonResult

11.3 Minimal request-handling APIs

11.3.1 An example minimal API

11.3.2 Parameters in minimal APIs

11.3.3 Minimal API return types

11.4 CSS Isolation in Razor Pages

Summary