Can a controller completely replace what the http handler does?

I want to know if the controller can completely replace the http handler when there was no view. The function looks similar.

+3
source share
1 answer

Of course:

public ActionResult Index()
{
    return Content("No view involved here", "text/plain");
}

or

public ActionResult Index()
{
    return File("test.pdf", "application/pdf");
}

or

public ActionResult Index()
{
    return Json(new { foo = "bar" });
}

In all of these examples, there is no representation. The controller acts as an HTTP handler.

+5
source

Source: https://habr.com/ru/post/1775983/


All Articles