asp.net-mvc - Controller 能完全取代 http handler 的功能吗?

标签 asp.net-mvc asp.net-mvc-2

我想知道 Controller 是否可以在不涉及 View 的情况下完全替代 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" });
}

在所有这些示例中,都没有涉及 View 。 Controller 充当 HTTP 处理程序。

关于asp.net-mvc - Controller 能完全取代 http handler 的功能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4233388/

相关文章:

jquery - 如何通过ajax jquery将列表字符串从 View 传递到 Controller

c# - 如何将 AdSense 代码添加到我的 ASP.NET MVC 网站?

c# - 我如何确保依赖属性(property)的其他人的属性(property)值(value)?

asp.net-mvc-3 - 是否应该尝试防止 MVC View 中的空引用异常/索引越界异常?

asp.net - 如何修改ajax工具ValidatorCalloutExtender的CSS

c# - 带有部分 CRUD 的 MVC 5 BeginCollectionItem

asp.net - 当服务器的物理路径为 UNC 格式时,我的系统管理员是否疯狂 :-) Does ASP. NET MVC 中断?

asp.net-mvc - .NET MVC : Map Route Using Attribute On Action

c# - Windows Azure http 重定向的最佳实践

asp.net-mvc-2 - ASP.NET MVC 默认 View 模型 cookie 到自定义对象的绑定(bind)