Upload
learningtech
View
799
Download
5
Embed Size (px)
Citation preview
ASP.NET MVC - ActionJASON
ASP.NET MVC-Action
What 「 Action method 」
Action attribute
Custom Action Result
Action of Controller
What 「 Action method 」 ?
Action of Controller
必須是 public
不可以是 static
不可以是 extension method
不可以是建構子、 getter 或 setter
不可以是 Generic method
不可以是 Controller baseClass method
不可以是 ControllerBase baseClass method
不可以包含 ref 或 out 參數 不能加上 「 NonAction 」 action selector attribute
NonAction Attribute
Represents an attribute that is used to indicate that a controller method is not an action method.
ChildActionOnly Attribute
Represents an attribute that is used to indicate that an action method should be called only as a child action.
Action View
Html.Action VS Html.RenderAction
Html.Action Invokes the specified child action method with the specified
parameters and returns the result as an HTML string.
Html.RenderAction Invokes the specified child action method and renders the result
inline in the parent view.
ActionName Attribute
Represents an attribute that is used for the name of an action.
Custom Action Results
不同 action ,相同 result , 導致重複的程式碼
action 裡,含有難以測試的程式碼
Custom Action Results 使用 action result 消除重複的程式碼
Custom Action Results 使用 action result 抽象化難以測試的相依性
Reference
Controllers and Action Methods in ASP.NET MVC Applications http://msdn.microsoft.com/en-US/library/dd410269(v=vs.100).aspx