views:

88

answers:

0

I am trying to create an ActionResult that behaves in exactly the same manner as a ViewResult but allows me to specify the Content-Type header. This is difficult because from what I can tell ASP.Net MVC hands off to the webforms rendering engine, which then sets the content type using the header on the page, this method isn't viable for me, it would be far easier if I could change this in one central place.

I have tried the following implementation but it doesn't work. The WebForms engine resets the type. the same happens if it is set afterwards. Or if you try to trick it using Headers.Add

public class MyViewResult : ViewResult
{
    public override void ExecuteResult(ControllerContext context)
    {
        context.HttpContext.Response.ContentType = "myContent";
        base.ExecuteResult(context);
    }
}