24 Using view components

 

This chapter covers

  • Using view components to generate content that is orthogonal to the main purpose of the application
  • Applying view components in views
  • Passing data to view components from the parent view
  • Using partial views to generate HTML content
  • Creating classes that are controllers and view components

I describe view components in this chapter, which are classes that provide action-style logic to support partial views; this means view components provide complex content to be embedded in views while allowing the C# code that supports it to be easily maintained. Table 24.1 puts view components in context.

24.1 Preparing for this chapter

24.1.1 Dropping the database

24.1.2 Running the example application

24.2 Understanding view components

24.3 Creating and using a view component

24.3.1 Applying a view component

24.4 Understanding view component results

24.4.1 Returning a partial view

24.4.2 Returning HTML fragments

24.5 Getting context data

24.5.1 Providing context from the parent view using arguments

24.5.2 Creating asynchronous view components

24.6 Creating view components classes

24.6.1 Creating a hybrid controller class

Summary