Book Image

ServiceStack 4 Cookbook

Book Image

ServiceStack 4 Cookbook

Overview of this book

Table of Contents (18 chapters)
ServiceStack 4 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Overriding Razor views or templates using attributes


One easy way to specify a view is to place a DefaultView attribute on either a service method or on an entire service class, or both. The attribute placed on the service class can apply as a default, while an attribute placed on a service method can override this default.

Getting ready

DefaultView takes two different arguments, a view and optionally a template. This allows you to specify each separately to control the rendering of the page.

The template parameter allows you to specify one of multiple templates. In a small application, you might only have one _Layout.cshtml, which would get picked up by default, and so you would not need to specify it. In a larger application, you might have a template for a microsite, another template for the home page, and another template for a content page. This allows you to group together pages that have a similar look and feel into separate templates.

The view parameter allows you as a developer to...