Skip to content

MahfuzHussien/WebApiContrib.Formatting.Razor

 
 

Repository files navigation

WebApiContrib.Formatting.Razor

A MediaTypeFormatter for generating HTML markup for ASP.NET Web API applications.

Get it from NuGet:

Install-Package WebApiContrib.Formatting.Razor

WebApiContrib.Formatting.Razor lets you return HTML markup using three different mechanisms:

  1. conventionally name the view the same as the return type
  2. return a View object
  3. attribute your return type with a ViewAttribute
  4. define the view mapping in a ViewConfig

You also need to register the formatter and set the GlobalViews.DefaultViewParser and GlobalViews.DefaultViewLocator:

GlobalConfiguration.Configuration.Formatters.Add(new HtmlMediaTypeViewFormatter());

GlobalViews.DefaultViewParser = new RazorViewParser();
GlobalViews.DefaultViewLocator = new RazorViewLocator();
// If using ViewConfig:
//ViewConfig.Register(GlobalViews.Views);

The GlobalViews configuration comes from the WebApiContrib.Formatting.Html project.

About

Web API formatter based on RazorViewEngine

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published