You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+28-7
Original file line number
Diff line number
Diff line change
@@ -10,17 +10,38 @@ Get it from [NuGet](http://nuget.org/packages/WebApiContrib.Formatting.Razor):
10
10
WebApiContrib.Formatting.Razor lets you return HTML markup using three different mechanisms:
11
11
12
12
1. conventionally [name the view](https://github.com/WebApiContrib/WebApiContrib.Formatting.Razor/tree/master/samples/MvcWebApiSiteTest/Views) the same as the [return type](https://github.com/WebApiContrib/WebApiContrib.Formatting.Razor/blob/master/samples/MvcWebApiSiteTest/Controllers/CustomerController.cs#L14)
13
-
2.[return a `View` object](https://github.com/WebApiContrib/WebApiContrib.Formatting.Razor/blob/master/samples/MvcWebApiSiteTest/Controllers/HomeController.cs#L10)
13
+
2.[return a `ViewResult` object](https://github.com/WebApiContrib/WebApiContrib.Formatting.Razor/blob/master/samples/MvcWebApiSiteTest/Controllers/HomeController.cs#L10)
14
14
3.[attribute your return type with a `ViewAttribute`](https://github.com/WebApiContrib/WebApiContrib.Formatting.Razor/blob/master/samples/MvcWebApiSiteTest/Controllers/CustomerController.cs#L21)
15
15
4. define the view mapping in a [`ViewConfig`](https://github.com/WebApiContrib/WebApiContrib.Formatting.Razor/blob/master/samples/MvcWebApiSiteTest/App_Start/ViewConfig.cs)
16
16
17
-
You also need to register the formatter and set the `GlobalViews.DefaultViewParser` and `GlobalViews.DefaultViewLocator`:
17
+
The simplest way to register Razor as a formatter is to use the `RazorViewFormatter`:
GlobalViews.DefaultViewParser = new RazorViewParser();
22
-
GlobalViews.DefaultViewLocator = new RazorViewLocator();
23
-
// If using ViewConfig:
24
-
//ViewConfig.Register(GlobalViews.Views);
23
+
The `RazorViewFormatter takes three, optional parameters:
24
+
25
+
1.`siteRootPath` specifies the root folder containing the view files. This looks in `~/Views` by default.
26
+
2.`viewLocator` specifies an instance of `IViewLocator`, which is set to `RazorViewLocator` by default.
27
+
3.`viewParser` specifies an instance of `IViewParser`, which is set to `RazorViewParser` by default.
28
+
29
+
You can pass these values into either `RazorViewFormatter` or `HtmlMediaTypeViewFormatter`. You may want to do this to use embedded view resources, for example.
//config.Formatters.Add(new HtmlMediaTypeViewFormatter(null, new RazorViewLocator(), new RazorViewParser()));
34
+
```
35
+
36
+
You may also want to register the `HtmlMediaTypeFormatter` using the default constructor and set the `GlobalViews.DefaultViewParser` and `GlobalViews.DefaultViewLocator`:
The [`GlobalViews`](https://github.com/WebApiContrib/WebApiContrib.Formatting.Html/blob/master/src/WebApiContrib.Formatting.Html/Configuration/GlobalViews.cs) configuration comes from the [WebApiContrib.Formatting.Html](https://github.com/WebApiContrib/WebApiContrib.Formatting.Html) project.
0 commit comments