Advice on working with current page in controller
I would like 开发者_开发技巧to have your comment on what you think about the following. I have a custom route that will resolve the current page and add it to RouteData object. Imagine a controller with an Index method, which of these scenarios is preferable. To take one parameter, current page as an argument to the index method or to have a property like this:
public Page CurrentPage { get { return RouteData.DataTokens ["CurrentPage"] as Page; }}
Personally I would prefer to have a controller action taking the page
parameter. Makes the code more readable and easier to unit test. Just by looking at the action signature you know exactly on what parameters it depends.
精彩评论