title: asp.net mvc partial view is caching my model values
body: <p>I am working on an asp.net mvc web application. and i have a WebGrid, where i added a Page-size drop-down list to enable users to select how many records they like to have per page.</p>
  
  <p>the Action method is:-</p>
  
  <pre><code> [OutputCache(CacheProfile = "NoCache")]
   public ActionResult Disposed(string filter = null, int page = 1, int? pageSize = null, string sort = "Technology.Tag", string sortdir = "ASC")
          {
              GridList&lt;DisposedResources&gt; gridrecords = repository.GetDisposedResourcesForGrid(filter, page, pageSize, sort, sortdir, "rack");
              ViewBag.PagedSizeOptions = new PageOptions().FilterOptions;
              if (Request.IsAjaxRequest())
              {
  
                  return PartialView("_disposed", gridrecords);
              }
              return View("Disposed", gridrecords);
          }
  </code></pre>
  
  <p>and here is the repository method :-</p>
  
  <pre><code>  public GridList&lt;DisposedResources&gt; GetDisposedResourcesForGrid(string filter, int page, int? pageSize, string sort, string sortdir, string resourcetype)
          {
              if (!pageSize.HasValue)
              {
                  pageSize = Int32.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["TechPageSize"]);
              }
  
              var records = new GridList&lt;DisposedResources&gt;();
              records.currentfilter = filter;
  
              records.TotalRecords = GetDisposedResourcesForGridCount(filter, resourcetype);
              records.hasNetworkInfo = false;
              records.hasSystemInfo = false;
              records.CurrentPage = page;
              records.PageSize = pageSize.Value;
              records.currentsort = sort;
              records.currentsortdir = sortdir;
              records.Content = tms.DisposedResources.Include(a=&gt;a.Technology).Where(x =&gt; (filter == null ||
                              (x.Technology.Tag.ToLower().StartsWith(filter.ToLower()))
  
                            ) &amp;&amp; x.ResourceType.ToLower() == resourcetype.ToLower())
                      .OrderBy(sort + " " + sortdir)
                      .Skip((page - 1) * pageSize.Value)
                      .Take(pageSize.Value).ToList();
              return records;
  
          }
  </code></pre>
  
  <p>the Disposed view is :-</p>
  
  <pre><code>@model  S.ViewModels.GridList&lt;S.Models.DisposedResources&gt;
  
  
  
  
  Show   @Html.DropDownList("FilterSize", new SelectList(ViewBag.PagedSizeOptions, "Value", "Text", ViewBag.pagesize ), new { @id= "FilterSize1",@class="SmallDropDown3"}) &lt;span class="hidden-phone"&gt;per page.&lt;/span&gt; 
  
  &lt;div id="disposed"&gt;
  
  @Html.Partial( "_disposed",Model)
  
  &lt;/div&gt;
  
  @section Scripts {
  
  
  
      &lt;script type="text/javascript"&gt;
          $("body").on('change', '#FilterSize1', function () {
  
              //$(SizeProgressSort).show();
              $.ajaxSetup({ cache: false });
              $.ajax({
                  type: "Get",
                  url: '@Url.Action("Disposed")',
  
                  data: { pageSize: $('#FilterSize1').val(), page: "1", sort: $('#currentsort').val(), sortdir: $('#currentsortdir').val() },
  
                  success: successFunc,
                  error: errorFunc
              });
  
              function successFunc(data, status) {
  
                  $('#disposed').html(data);
  
  
              }
  
              function errorFunc() {
                  alert('error');
              }
          });
  
      &lt;/script&gt;
  }
  </code></pre>
  
  <p>and the _disposed partial view is:-</p>
  
  <pre><code>@model  S.ViewModels.GridList&lt;S.Models.DisposedResources&gt;
  
  
  
          var gridcolumns = new List&lt;WebGridColumn&gt;();
          gridcolumns.Add(new WebGridColumn()
          {
              ColumnName = "Technology.Tag",
              Header = Html.DisplayNameFor(model =&gt; model.Content.FirstOrDefault().Technology.Tag).ToString(),
              CanSort = true
          });
         //code goes here...
              var grid = new WebGrid(
                          canPage: true,
                          rowsPerPage: Model.PageSize,
                          canSort: true,
                          ajaxUpdateContainerId: "grid");
  
              grid.Bind(Model.Content, rowCount: Model.TotalRecords, autoSortAndPage: false);
              grid.Pager(WebGridPagerModes.All);
  
              @grid.GetHtml(htmlAttributes: new { id = "grid" },   // id for ajaxUpdateContainerId parameter
              fillEmptyRows: false,
              tableStyle: "table table-bordered table-hover",
              mode: WebGridPagerModes.All,
              columns: gridcolumns
  
              );
              }
               &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;
  &lt;input type="hidden" value="@Model.currentsort" id="currentsort" /&gt; @Model.currentsort
  &lt;input type="hidden" value="@Model.currentsortdir" id="currentsortdir" /&gt; @Model.currentsortdir
  </code></pre>
  
  <p>the problem i am facing is that the two parameters; <code>currentsort + currentsortdir</code> which are being passed as part of the javascript will not be changed,and the user will loose the current sort order if he chose to chnage the page size drop down-list. so can anyone advice what is the problem, now even if i chose to display the two values:-</p>
  
  <pre><code>Model.currentsort
  
  &amp;
  
  Model.currentsortdir
  </code></pre>
  
  <p>they will always have the defualt value, although these values are being changed inside the repository method... but seems the partial view is somehow caching the old values for these two parameter ?</p>