Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Session MVC5模型绑定_Session_Asp.net Mvc 5_Model Binding - Fatal编程技术网

Session MVC5模型绑定

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

我使用MVC5和ASP.NET。我想使用模型绑定。如何在模型绑定中获取会话对象

   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;
    }
}