Session MVC5模型绑定
我使用MVC5和ASP.NET。我想使用模型绑定。如何在模型绑定中获取会话对象Session MVC5模型绑定,session,asp.net-mvc-5,model-binding,Session,Asp.net Mvc 5,Model Binding,我使用MVC5和ASP.NET。我想使用模型绑定。如何在模型绑定中获取会话对象 public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { //I need session here } 是否正在创建自定义的ModelBinder?要做什么(我看不出在此上下文中需要会话中的对象的原因)?HttpContext.Current.se
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
//I need session here
}
是否正在创建自定义的
ModelBinder
?要做什么(我看不出在此上下文中需要会话中的对象的原因)?HttpContext.Current.session
?我发现了自己的错误。我用错误的活页夹实现了它。我已经从System.Web.Mvc.IModelBinder和ControllerContext参数中实现了它。
public class SessionPictureModelBinder:System.Web.Mvc.IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var obj = controllerContext.HttpContext.Session["MyKey"];
return obj;
}
}