c# - 如何使用 asp.net mvc View 返回 404

标签 c# .net asp.net-mvc

如何实现以下功能?

我的 Controller :

if (something == null)
{         
     //return the view with 404 http header
     return View();          
}

  //return the view with 200 http header
  return View();

最佳答案

随便写

Response.StatusCode = 404;

在返回 View 之前。

关于c# - 如何使用 asp.net mvc View 返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13764685/

相关文章:

c# - .NET 2.0 Web 服务 WSDL 错误元素被忽略?

.net - 使用客户可用的 Web 服务实现应用程序的最佳方式,还可以从第 3 方的 Web 服务获取信息

c# - 64 位 Windows 服务器中的 Sybase 驱动程序错误

c# - 异常处理 ASP .NET Core MVC 6

c# - 网络请求 : The underlying connection was closed

c# - 如何锁定文件

c# - 以编程方式在类的每个属性上插入方法调用

c# - 我将如何通过依赖注入(inject)传递 Web API 请求?

asp.net-mvc - 发布应用程序时的 .Net Core React SPA 路由问题

asp.net-mvc - ASP .NET MVC 在 View 之间存储大量参数