18 Building forms with Tag Helpers

 

This chapter covers

  • Building forms easily with Tag Helpers
  • Generating URLs with the Anchor Tag Helper
  • Using Tag Helpers to add functionality to Razor

In chapter 17 you learned about Razor templates and how to use them to generate the views for your application. By mixing HTML and C#, you can create dynamic applications that can display different data based on the request, the logged-in user, or any other data you can access.

Displaying dynamic data is an important aspect of many web applications, but it’s typically only half of the story. As well as needing to display data to the user, you often need the user to be able to submit data back to your application. You can use data to customize the view or to update the application model by saving it to a database, for example. For traditional web applications, this data is usually submitted using an HTML form.

In chapter 16 you learned about model binding, which is how you accept the data sent by a user in a request and convert it to C# objects that you can use in your Razor Pages. You also learned about validation and how important it is to validate the data sent in a request. You used DataAnnotations attributes to define the rules associated with your models, as well as associated metadata like the display name for a property.

18.1 Catering to editors with Tag Helpers

18.2 Creating forms using Tag Helpers

18.2.1 The Form Tag Helper

18.2.2 The Label Tag Helper

18.2.3 The Input and Textarea Tag Helpers

18.2.4 The Select Tag Helper

18.2.5 The Validation Message and Validation Summary Tag Helpers

18.3 Generating links with the Anchor Tag Helper

18.4 Cache-busting with the Append Version Tag Helper

18.5 Using conditional markup with the Environment Tag Helper

Summary

sitemap