asp.net-core-mvc - MVC6中的HttpConflict在哪里?

标签 asp.net-core-mvc

我是一个没有“Web 东西”经验的 C++ 人员,但我的主管希望我去学习“ASP.NET MVC 6”的方法,因为它是最新的时髦东西。

我设法掌握了至少一个教程,但我在任何地方都没有看到任何引用资料和文档。我在哪里可以查找有哪些类和方法?

我当前的问题是我试图弄清楚如何从 Controller 中的 Create 方法返回 409 的 Http 状态。我没有看到 HttpConflict 方法。我该怎么称呼?

最佳答案

在 ASP.NET Core 1.0 中,您可以使用任何 Controller 上可用的 StatusCode(int statusCode) 方法。

[HttpPost]
public IActionResult Create([FromBody] Widget item)
{
  // ...

  // using the HttpStatusCode enum keeps it a little more readable
  return StatusCode((int) HttpStatusCode.Conflict); 
}

关于asp.net-core-mvc - MVC6中的HttpConflict在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33179998/

相关文章:

c# - Json 无法解析 ajax post 请求

c# - 如何在 ASP.NET Core MVC 中请求并显示实时 Web api 数据?

c# - 在 ASP.NET MVC [非静态] 中声明全局 Razor 页面变量

c# - 名称为( Controller 名称)的 RedirectToAction 无法定位操作

c# - ASP.NET Core 2.1 Razor Form,Post 未到达 Controller

c# - 如何在没有 Entity Framework 提供程序的情况下在 .net core 中实现谷歌登录

c# - 操作无法完成。无效指针 - Visual Studio 2015 Update 3

razor - 在 View 中显示对象 ToString() 值

asp.net-core-mvc - 使用 Visual Studio 2017 MVC ASP.NET Core 进行发布 "They must have the same number of items"

c# - ASP.NET 5 中所有类型的 http header 都去了哪里?