12
ASP.NET MVC - Action JASON

Asp.net controller

Embed Size (px)

Citation preview

Page 1: Asp.net controller

ASP.NET MVC - ActionJASON

Page 2: Asp.net controller

ASP.NET MVC-Action

What 「 Action method 」

Action attribute

Custom Action Result

Page 3: Asp.net controller

Action of Controller

What 「 Action method 」 ?

Page 4: Asp.net controller

Action of Controller

必須是 public

不可以是 static

不可以是 extension method

不可以是建構子、 getter 或 setter

不可以是 Generic method

不可以是 Controller baseClass method

不可以是 ControllerBase baseClass method

不可以包含 ref 或 out 參數 不能加上 「 NonAction 」 action selector attribute

Page 5: Asp.net controller

NonAction Attribute

Represents an attribute that is used to indicate that a controller method is not an action method.

Page 6: Asp.net controller

ChildActionOnly Attribute

Represents an attribute that is used to indicate that an action method should be called only as a child action.

Action View

Page 7: Asp.net controller

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.

Page 8: Asp.net controller

ActionName Attribute

Represents an attribute that is used for the name of an action.

Page 9: Asp.net controller

Custom Action Results

不同 action ,相同 result , 導致重複的程式碼

action 裡,含有難以測試的程式碼

Page 10: Asp.net controller

Custom Action Results 使用 action result 消除重複的程式碼

Page 11: Asp.net controller

Custom Action Results 使用 action result 抽象化難以測試的相依性

Page 12: Asp.net controller

Reference

Controllers and Action Methods in ASP.NET MVC Applications http://msdn.microsoft.com/en-US/library/dd410269(v=vs.100).aspx