Refer to "Pro ASP.NET MVC 2 Framework", ActionResult is an implementation of Command Pattern. I'd like to know how the pattern is implemented here? Can you send me some light?
Thank you.
An action method returns an instance that embodies a command that the framework needs to perform next. This provides a means for delaying the execution of framework/pipeline code until after the action method is complete, rather than from within the action method.
This command represented by the ActionResult abstract class and posses the ExecuteResult method which is implemented by concrete commands such as ViewResult
and JsonResult
:
The ActionResult is not an implementation of command pattern at all. The Action on the Controller is the closest to the command, and the ActionResult is the alteration to the View, typically. The command updates models, ActionResults do not update models.
I implemented the command pattern in MVC by using an ActionFilter and storing the Action, Controller name, and Parameters in a history (eg: a List<>). One controller implemented Undo and Redo, while all other controllers followed the convention of having all actions prefixed with Do_ and Undo_. Alternatively you could pass an additional bool? undoing parameter.
There are many ways of doing Command in MVC, but ActionResult has nothing to do with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With