MSDN控制器基類地址:https://msdn.microsoft.com/zh-cn/library/system.web.mvc.actionresult.aspx?f=255&MSPPError=-2147217396
一:ActionResult
操作方法通過執行工作並返回操作結果來響應用戶輸入。 操作結果表示框架將代表操作方法執行的命令。 ActionResult 類是操作結果的基類。
以下類型從 ActionResult 派生:
二、IHttpActionResult
- Json<T>(T content)
return Json<List<ORDER>>(lstRes);
- Ok()、 Ok<T>(T content)
return Ok();
return Ok<string>(name);
- NotFound()
return NotFound();
當需要向客戶端返回找不到記錄時,有時需要用到NotFound()方法
NotFound()方法會返回一個404的錯誤到客戶端。
三:其他
-
Content<T>(HttpStatusCode statusCode, T value)
[HttpGet] public IHttpActionResult GetContentResult() { return Content<string>(HttpStatusCode.OK, "OK"); }
向客戶端返回值和http狀態碼。
-
BadRequest()
向客戶端返回400的http錯誤。
-
Redirect(string location)
[HttpGet] public IHttpActionResult RedirectResult() { return Redirect("http://localhost:21528/api/Order/GetContentResult"); }
將請求重定向到其他地方。