主要用到: HttpStatusCodeResult 和HttpStatusCode 的http返回状态
比如:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
/// <summary> /// 使用异步模式 /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task<ActionResult> Details(int? id) { //参数不正确,直接抛出对应的HttpStatusCodeResult结果 if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } //todo return View(); } public ActionResult Details(int? id) { //参数不正确,直接抛出对应的HttpStatusCodeResult结果 if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } //todo return View(); }