Alex Rivera | Logout

Writing to Output Stream from Action

Asked 2009-06-03T04:56:34.050
32

For some strange reasons, I want to write HTML directly to the Response stream from a controller action. (I understand MVC separation, but this is a special case.)

Can I write directly into the HttpResponse stream? In that case, which IView object should the controller action should return? Can I return 'null'?

Edit
Report

1 Answer

10

Yes, you can write directly to the Response. After you're done, you can call CompleteRequest() and you shouldn't need to return anything.

For example:

// GET: /Test/Edit/5
public ActionResult Edit(int id)
{

    Response.Write("hi");
    HttpContext.ApplicationInstance.CompleteRequest();

    return View();     // does not execute!
}
answered 2009-06-03T05:00:21.360

Your Answer