title: How to call function from within a partialview that reloads the partialview itself
body: <p>I have a MVC Index View with a link that, on click, calls a JQuery method that fires off an Ajax POST to dynamically load a PartialView into a div.</p>
  
  <p><strong>Inside</strong> the PartialView I have a form that, when submitted, needs to reload itself (the PartialView), into the div in the Index View.</p>
  
  <p>When I try the code below it gives a memory exception in Visual Studio.</p>
  
  <p>How do I 'reload' the partialview like this?  Can I reference the div in the main (containing) View from the PartialView?  </p>
  
  <p>Relevant code snippets below</p>
  
  <p><strong>Index View</strong></p>
  
  <pre><code>&lt;a href="#" class="buttonId currentplayer" data-userteamid="60" data-footballclub="" data-searchstring=""&gt;click to load game 60&lt;/a&gt; 
  
  &lt;div id="teampartial"&gt;&lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  var returnTeam = function (link) {
      debugger;
      var userTeamId = $(link).attr('data-userteamid');
      var footballClub = $(link).attr('data-footballclub');
      var searchString = $(link).attr('data-searchstring');
      $.ajax({
          type: 'POST',
          url: '/ViewPlayers/TeamOverView',
          data: {
              userTeamId: userTeamId,
              footballClub: footballClub,
              searchString: searchString
          },
          success: function (data) {
              $('#teampartial').empty();
              $('#teampartial').append(data);
          }
      });
  };
  
  $('.buttonId').click(function () {
      returnTeam(this);
  });
  </code></pre>
  
  <p></p>
  
  <p><strong>Controller Action</strong></p>
  
  <pre><code>[HttpPost]
      public ActionResult TeamOverView(int userTeamId, string footballClub, string searchString)
      {
          var _teamOverView = _service.GetTeamOverViewViewModel((int)userTeamId, footballClub, searchString);
          return PartialView("teamdetails", _teamOverView);
      }
  </code></pre>
  
  <p><strong>Team Details PartialView</strong></p>
  
  <pre><code>&lt;h2&gt;List of Players&lt;/h2&gt;
              using (Html.BeginForm("TeamOverView", "ViewPlayers", FormMethod.Post,new { id = "filterPlayers" }))
              {
                  &lt;p&gt; 
                      @Html.DropDownListFor(x =&gt; x.Clubs, new SelectList(Model.Clubs,"Value","Text"), "All")
                      Name: @Html.TextBox("searchString") 
                      &lt;input type="hidden" name="userTeamID" value="@Model.UserTeamId" /&gt;
                      &lt;input type="submit" value="Filter" /&gt;
                  &lt;/p&gt;
              }
              &lt;table&gt;
                  @foreach (var item in Model.PlayersSearchedFor)
                  {
                      &lt;tr&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.Name)
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  }
              &lt;/table&gt;
  
  &lt;script type="text/javascript"&gt;
      var returnSelectTeam = function () {
          debugger;
          $.ajax({
              type: 'POST',
              url: '/ViewPlayers/TeamOverView',
              data: $("#filterPlayers").serialize(),
              success: function (data) {
                  $('#teampartial').empty();
                  $('#teampartial').append(data);
              }
          });
      };
  
      $('#filterPlayers').submit(function () {
          returnSelectTeam();
      });
  &lt;/script&gt;
  </code></pre>