Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class ViewDataForActivation
public ViewDataDictionary ViewData { get; set; }
public class ViewOutputFormatter : Microsoft.AspNet.Mvc.OutputFormatter
public ViewOutputFormatter()
public override Task WriteResponseBodyAsync(OutputFormatterContext context)
var activator = (IControllerActivator)context.ActionContext.HttpContext.RequestServices.GetService(typeof(IControllerActivator));
var forActivation = new ViewDataForActivation();
activator.Activate(forActivation, context.ActionContext);
var viewData = forActivation.ViewData;
viewData.Model = context.Object;
var result = new ViewResult();
result.ViewData = viewData;
return result.ExecuteResultAsync(context.ActionContext);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment