控制器可以完全替代http处理程序吗?

问题描述:

我想知道当没有视图涉及时,控制器是否可以完全替代http处理程序。该功能看起来相似。控制器可以完全替代http处理程序吗?

肯定的:

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

或:

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

或:

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

在所有这些例子中,没有涉及视图。该控制器充当一个HTTP处理程序。