title: How can I refresh a partial view on the main index page on a submit from a separate partial view modal
body: <p>I have a main index page that loads a partial view that contains a dropdownfor list.  The selection of an item from the ddl populates controls in a separate partial view for display.  Clicking Edit pops open a model with a Form of EditorFor controls bound to the model properties for the selected item.  When the submit button for the modal is clicked. It posts back the form for updating to the database...at which point I want to basically refresh the partial view that contains the dropdownlist so that it reflects the changes is appropriate.</p>
  
  <p>The code I have performs all the basic mechanics without issue EXCEPT for refreshing the partial view that contains the dropdownlistfor control.  I could just do a redirecttoaction for the index page and refresh the entire page but I would prefer to only refresh the partial view.  I can not figure out how to make this happen and am wondering if someone has a suggestion.</p>
  
  <p>The code div code for the index page is:</p>
  
  <pre><code>@{
      ViewBag.Title = "Index";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  &lt;br /&gt;
  &lt;div class="partialContent" data-url="/Database/GetDatabases"&gt;
         @Html.Partial("_GetDatabases")
      &lt;/div&gt;
  &lt;br /&gt;
  
  
  &lt;div class="modal fade" id="modalEditDBInfo" role="application" aria-labelledby="modalEditDBInfoLabel" aria-hidden="true"&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modalEditDBInfoContent" style="background-color:white; border-radius:10px; box-shadow:10px;"&gt;
              @Html.Partial("_EditDatabaseInfo")
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The code for the EditDatabase  partial view</p>
  
  <pre><code>@model Hybridinator.WebUI.Models.DatabaseModel
  &lt;br /&gt;
  &lt;br /&gt;
  
  &lt;div class="modal-header"&gt;
      &lt;button type="button" class="close" data-dismiss="modal"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;span class="sr-only"&gt;Close&lt;/span&gt;&lt;/button&gt;
      &lt;h4 class="modal-title" id="editModelTitle"&gt;Edit Database Info&lt;/h4&gt;
  &lt;/div&gt;
  @if(Model != null)
  { 
      using (Html.BeginForm("EditDatabaseInfo", "Database", FormMethod.Post, new { @class = "modal-form" }))
      {
          &lt;div class="modal-body"&gt;
              @Html.HiddenFor(m =&gt; m.database_pk, new { htmlAttributes = new { @class = "form-control" } })
              &lt;div class="form-group"&gt;
                  &lt;div id="databaselabel"&gt;@Html.LabelFor(m =&gt; m.database_name, "Database")&lt;/div&gt;
                  &lt;div id="databaseedit"&gt;@Html.EditorFor(m =&gt; m.database_name, new { htmlAttributes = new { @class = "form-control" } })&lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;div id="databaseserverlabel"&gt;@Html.LabelFor(m =&gt; m.database_server, "Database Server")&lt;/div&gt;
                  &lt;div id="databaseserveredit"&gt;@Html.EditorFor(m =&gt; m.database_server, new { htmlAttributes = new { @class = "form-control" } })&lt;/div&gt;
              &lt;/div&gt;
  
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;div id="editsqltypelabel"&gt;@Html.LabelFor(m =&gt; m.sql_type_pk, "Sql Type")&lt;/div&gt;
                  &lt;div id="editsqltypeddl"&gt;@Html.DropDownListFor(m =&gt; m.sql_type_pk, Model.sqlTypes)&lt;/div&gt;
              &lt;/div&gt;
  
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
                  &lt;button class="btn btn-inverse btn-primary" type="submit"&gt;Save&lt;/button&gt;
              &lt;/div&gt;
      }       
  }
  </code></pre>
  
  <p>The code for the GetDatabases partial view</p>
  
  <pre><code>@model Hybridinator.WebUI.Models.DatabaseListModel
  @if(Model != null)
  {    
      &lt;div id="databasedropdown" class="container-fluid"&gt;
          @Html.Label("Databases: ")@Html.DropDownListFor(m =&gt; m.database_pk, Model.databases, "Select one...", new { @id = "database_pk", onchange = "changeDatabase()" })  
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>The Controller code for GetDatabases</p>
  
  <pre><code>public ActionResult GetDatabases()
          {
              DatabaseListModel databaseListModel = new DatabaseListModel
              {
                  databases = databaseService.GetUndeletedDatabaseList().
                      Select(d =&gt; new SelectListItem
                      {
                          Value = d.database_pk.ToString(),
                          Text = d.database_name
                      }).ToList()
              };
              return PartialView("_GetDatabases",databaseListModel);
          }
  </code></pre>
  
  <p>and last the code for both the Get and Post for the EditDatabase modal</p>
  
  <pre><code>[HttpGet]
  public ActionResult EditDatabaseInfo(int database_pk)
  {
      DatabaseModel databaseModel = FillDatabaseModelByDatabasePK(database_pk);
      return PartialView("_EditDatabaseInfo", databaseModel);
  }
  [HttpPost]
  public ActionResult EditDatabaseInfo(DatabaseModel databaseModel)
  {
      string[] result = databaseService.Update(new Database
      {
          database_pk = databaseModel.database_pk,
          database_name = databaseModel.database_name,
          database_password = databaseModel.database_password,
          database_username = databaseModel.database_username,
          database_server = databaseModel.database_server,
          hist_database_name = databaseModel.hist_database_name,
          hist_database_server = databaseModel.hist_database_server,
          hist_database_password = databaseModel.hist_database_password,
          hist_database_username = databaseModel.hist_database_username,
          sqlType = new SQLType { sql_type_pk = databaseModel.sql_type_pk }
      });
      return RedirectToAction("GetDatabases");
  }
  </code></pre>
  
  <p>As I said the RedirectToAction("Index)  returned in the Post  EditDatabase  controller method works in a pinch..but I really dont want to have to refresh the whole page.  I assume there is something I can do differently in the return on that method to just reload the GetDatabases partial  but I can't figure it out.  Any help would be appreciated.</p>