title: How to properly clear GridViewExtension data on page revisit or reload?
body: <p><strong>Background</strong></p>
  
  <p>I have an incomplete project built on MVC 5, EF 6 DB First &amp; DevExpress extensions with following code spec (all original non-English variable names changed &amp; entire code simplified to comply MCVE):</p>
  
  <p>Model (Namespace: <code>ProjectName.Models</code>)</p>
  
  <pre><code>public class DBContext : DbContext
  {
      public DBContext : base("ConnectionStringName")
      {
          public DbSet&lt;WinnerTable&gt; Winners { get; set; }
          public DbSet&lt;UnitTable&gt; Units { get; set; }
          public DbSet&lt;CustomerTable&gt; Customers { get; set; }
      }
  }
  
  [Table("WinnerTable")]
  public class WinnerModel : IWinnerRepository
  {
      public String WinnerID { get; set; }
      public String CustomerID { get; set; }
      public String CustomerName { get; set; }
      public String TranDate { get; set; }
  
      public List&lt;UnitModel&gt; UnitList { get; set; }
  
      public List&lt;UnitModel&gt; GetUnitList(String sessionID, DateTime tranDate)
      {
          // query to unit list
          using (var DB = new DBContext())
          {
              var query = (from unit in DB.Units
                           where unit.SessionID == sessionID &amp;&amp; unit.TranDate = tranDate
                           select new UnitModel() 
                           {
                                // unit table to unit model definition
                           }).ToList();
              return query;
          }
      }
  }
  
  [Table("UnitTable")]
  public class UnitModel
  {
      public String UnitID { get; set; }
      public String UnitName { get; set; }
      // other definitions
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>using ProjectName.Models;
  
  [RoutePrefix("Input")]
  public class InputController : Controller
  {
      [HttpGet]
      public ActionResult Winner()
      {
          WinnerModel model = new WinnerModel()
          {
              // default values on first visit/reload page
              TranDate = DateTime.Now.Date,
              UnitList = new List&lt;UnitModel&gt;(); // list declaration
          }
          return View(model);
      }
  
      public PartialViewResult CustomerData(String customerId, String sessionId, DateTime tranDate, WinnerModel model)
      {
          if (DevExpressHelper.IsCallback &amp;&amp; !String.IsNullOrEmpty(customerId))
          {
              Session["CustomerID"] = customerId;
              Session["SessionID"] = sessionId;
              Session["TranDate"] = Convert.ToDateTime(tranDate);
  
              using (var DB = new DBContext())
              {
                  var query = DB.Customers.Where(c =&gt; c.CustomerID == customerId).FirstOrDefault();
                  // model property assignments
              }
          }
  
          return PartialView("_CustomerData", model);
      }
  
      public PartialViewResult ShowItemsGrid(WinnerModel model)
      {
          String customerId = (Session["CustomerId"] ?? String.Empty).ToString();
          String sessionId = (Session["SessionId"] ?? String.Empty).ToString();
          String lastCustomer = (Session["LastCustomer"] ?? String.Empty).ToString();
          DateTime tranDate = Convert.ToDateTime(Session["TranDate"] ?? DateTime.Now.Date);
  
          using (var DB = new DBContext())
          {
              model.CustomerId = customerId;
              model.SessionId = sessionId;
              model.TranDate = tranDate;
  
              model.UnitList = model.GetUnitList(sessionId, tranDate);
  
              if (model.UnitList == null || model.UnitList.Count == 0)
              {
                  model.UnitList = new List&lt;UnitModel&gt;();
              }
  
              Session["LastCustomer"] = lastCustomer;
  
              return PartialView("_GridView", model);
          }
      }
  }
  </code></pre>
  
  <p>View (Winner.cshtml)</p>
  
  <pre><code>@using ProjectName.Models
  
  @model WinnerModel
  
  @Html.EnableUnobtrusiveJavascript()
  
  &lt;script type="text/javascript"&gt;
     var customer = null;
  
     function initializeGrid()
     {
         ItemsGrid.PerformCallback(); // routine check if customer name exists
     }
  
     function comboChanged(s, e) {
         customer = s.GetValue();
         CustomerDataPanel.PerformCallback(); // callback to fill customer data for partial view &amp; load units into gridview
     }
  
     // callback to insert values into session variable
     function customerBeginCallback(s, e) {
         e.customArgs["customerId"] = customer;
         e.customArgs["sessionId"] = SessionId.GetValue();
         e.customArgs["tranDate"] = TranDate.GetValue();
     }
  
     function customerEndCallback(s, e) {
         ItemsGrid.PerformCallback();
     }
  
     // count checked data inside gridview
     // this may be asked on other context and doesn't matter for this one
     function countUnits(buttonName, url)
     {
         // other code
     }
  &lt;/script&gt;
  
  @using (Html.BeginForm("Winner", "Input", FormMethod.Post))
  {
      Html.DevExpress().TextBoxFor(m =&gt; m.SessionId, TextBoxSettings).GetHtml();
  
      Html.DevExpress().DateEditFor(m =&gt; m.TranDate, DateEditSettings).GetHtml(); 
  
      // this combobox has client-side event SelectedIndexChanged = "comboChanged"
      // GetCustomers method just populate customers data into combobox and unrelated to this problem
      Html.DevExpress().ComboBoxFor(m =&gt; m.CustomerId, ComboBoxSettings).BindList(ProjectName.Providers.GetCustomers()).GetHtml();
  
      Html.RenderPartial("_CustomerData", Model); // DX callback panel
  
      Html.RenderPartial("_GridView", Model);
  
      // button to count all checked values inside gridview
      Html.DevExpress().Button(CountButtonSettings).GetHtml();
  
      Html.DevExpress().LabelFor(m =&gt; m.TotalPrice, PriceLabelSettings).GetHtml();
  
      // button for submit &amp; reset form here
      Html.DevExpress().Button(SubmitButtonSettings).GetHtml();
      Html.DevExpress().Button(ResetButtonSettings).GetHtml();
  }
  </code></pre>
  
  <p>Partial View (_CustomerData.cshtml)</p>
  
  <pre><code>@using ProjectName.Models
  
  @model WinnerModel
  
  @{
      // MVC DX callback panel for customer details
      // Name = CustomerDataPanel
      // CallbackRouteValues: Controller = Input, Action = CustomerData 
      // ClientSideEvents.BeginCallback = customerBeginCallback
      // ClientSideEvents.EndCallback = customerEndCallback
  
      Html.DevExpress().CallbackPanel(CallbackPanelSettings).GetHtml();
  }
  </code></pre>
  
  <p>Partial View (_GridView.cshtml)</p>
  
  <pre><code>@using ProjectName.Models
  
  @model WinnerModel
  
  @{
      // MVC DX GridView with row selection checkboxes
      // The gridview column structure is exactly same as UnitModel has
      // Name = ItemsGrid
      // CallbackRouteValues: Controller = Input, Action = ShowItemsGrid
      // ClientSideEvents.Init = initializeGrid
  
      GridViewExtension grid = Html.DevExpress().GridView(GridViewSettings); 
      grid.Bind(Model.UnitList).GetHtml(); // grid bound to List&lt;UnitModel&gt;
  }
  </code></pre>
  
  <p>All gridview changes require sufficent privileges (i.e. admin/supervisor).</p>
  
  <p><strong>Problem Statement</strong></p>
  
  <p>I want anyone help finding out where and how proper routine codes to empty gridview data must be attached on controller method(s) to give expected results. As I tried so far, the gridview still maintaining its previous state given from session variable when <code>Winner</code> page revisited or reloaded (immediate first visit after login worked because all session variables are empty, thus no data was populated to gridview).</p>
  
  <p>Additionally, I want to show JS confirm message when user trying to close/reload <code>Winner</code> page while some/all gridview data are being checked.</p>
  
  <p><strong>Expected Results</strong></p>
  
  <ol>
  <li>For every first visit, revisit &amp; reload on <code>Winner</code> page, the gridview content must empty.</li>
  <li>After a user provides certain customer ID, the gridview will populated with some unit data from unit table, where changes inside it immediately lost when user accepts reloading/closing page confirm message.</li>
  </ol>
  
  <p>Any kind of answers or suggestions will appreciated.</p>