Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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
C# 当前会话工作异常_C#_Asp.net_Asp.net Mvc_Session - Fatal编程技术网

C# 当前会话工作异常

C# 当前会话工作异常,c#,asp.net,asp.net-mvc,session,C#,Asp.net,Asp.net Mvc,Session,我对HttpContext.Current.Session[“someSession”]有疑问 在我的网站中,我有一个空的网格,用户可以在网格的编辑模式下添加一些行。当用户插入新行时,我将其存储在会话中,因此我有以下类: public static class DocumentSessionRepository { public static IList<DocumentModel> AllDocuments() { return (IList<

我对HttpContext.Current.Session[“someSession”]有疑问

在我的网站中,我有一个空的网格,用户可以在网格的编辑模式下添加一些行。当用户插入新行时,我将其存储在会话中,因此我有以下类:

public static class DocumentSessionRepository
{
    public static IList<DocumentModel> AllDocuments()
    {
        return (IList<DocumentModel>)HttpContext.Current.Session["Documents"];
    }

    public static void Insert(DocumentModel product)
    {
        AllDocuments().Add(product);
    }

    public static void Delete(Guid? idDocument)
    {
        var target = GetOneDocument(p => p.IDDocument == idDocument);
        AllDocuments().Remove(target);
    }

    public static DocumentModel GetOneDocument(Func<DocumentModel, bool> id)
    {
        var one = AllDocuments().Where(id).FirstOrDefault();
        return one;
    }
}
查看在此会话中绑定网格的位置

  @(Html.Telerik()
      .Grid<DocumentModel>()
      .BindTo((List<DocumentModel>)DocumentSessionRepository.AllDocuments())
@(Html.Telerik()
.Grid()
.BindTo((列表)DocumentSessionRepository.AllDocuments())

假设问题出现在
IList
实例中。如果此实例为所有用户共享,则会话是否特定于用户并不重要。看起来所有会话都共享同一个实例。请检查类实例化,例如,如果该类在静态字段中实例化,并且该字段存储在会话中,则所有用户都将我也有这个例子


我100%确定
Current.Session
工作正常。

您在哪里设置
HttpContext.Current.Session[“文档”]
?@I或者查看我在OP上的编辑。谢谢。
  @(Html.Telerik()
      .Grid<DocumentModel>()
      .BindTo((List<DocumentModel>)DocumentSessionRepository.AllDocuments())