MVC小系列(二十)【给Action提供HttpStatusCodeResult】
主要用到: HttpStatusCodeResult 和HttpStatusCode 的http返回状态
比如:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.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(); }