例如:
class MyContoller
{
[MyCustomAttribute]
public ActionResult MyAction(ModelX fromRequest, ModelY fromSession, ModelZ fromCookie)
{
string productId = fromRequest.ProductId;
string userId = fromSession.UserId;
string cultureName = fromCookie.CultureName;
}
}
理由:
我不想访问控制人员的请求、会议以及HttpContext,以及MVC3的默认想法,即把模型推向行动是非常巨大的。
I want the number of parameters of MyAction is easy to change. For example, if I add a new parameter, the system will try to look for values in Request, Session or Cookies by the name or type of the parameter (I think custom ModelBinders may be required for cookie values) and pass the filled model to my action. I don t have to write extra code.
习俗归属(例如,MyCustomAttribute)能否实现这一想法?