2013-01-16 57 views
1

根據我的理解,它是一個類,可以返回一個視圖 ,因爲基於某些操作,我試圖執行視圖。什麼是動作結果?

請確認是否正確。

回答

4

ActionResult爲各種結果,可以從一個動作方法返回基類。它不一定是必需的觀點。有很多的選擇有什麼動作的結果可能是:

  • ContentResult - 用戶自定義的內容
  • EmptyResult - 只是一句
  • FileResult - 二進制文件
  • HttpStatusCodeResult - 特定的HTTP響應狀態代碼和說明
  • JavaScriptResult - js代碼
  • JsonResult - 數據格式爲JSON
  • RedirectResult - 重定向到URL
  • RedirectToRouteResult - 重定向到一些MVC路線
  • ViewResult - 這實際上是認爲
  • PartialView - 局部視圖

爲什麼你看到它在大多數例子爲理由從行動返回的價值是,你可以有:

public ActionResult MyAction() 
{ 
    if(someCondition) 
     return View(); // return the view from action 
    else 
     return RedirectToAction("SomeOtherAction","OnSomeOtherController"); // redirect to other action 
}