6

Ho un modulo di ricerca che è un modulo Ajax. All'interno del modulo è presente una DropDownList che, una volta modificata, dovrebbe aggiornare un PartialView all'interno del modulo Ajax (tramite una richiesta GET). Tuttavia, non sono sicuro di cosa fare per aggiornare PartialView dopo aver ripristinato i risultati tramite la richiesta GET.ASP.NET MVC - Aggiorna PartialView quando DropDownList è stato modificato

Search.aspx

<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> 
    Search 
</asp:Content> 

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#Sections").change(function() { 

      var section = $("#Sections").val(); 
      var township = $("#Townships").val(); 
      var range = $("#Ranges").val(); 

      $.ajax({ 
       type: "GET", 
       url: "Search/Search?section=" + section + "&township=" + township + "&range=" + range, 
       contentType: "application/json; charset=utf-8", 
       dataType: "html", 
       success: function (result) { 
        // What should I do here to refresh PartialView? 
       } 
      }); 
     }); 

    }); 
</script> 

    <h2>Search</h2> 

    <%--The line below is a workaround for a VB/ASPX designer bug--%> 
    <%=""%> 
    <% Using Ajax.BeginForm("Search", New AjaxOptions With {.UpdateTargetId = "searchResults", .LoadingElementId = "loader"})%>   
     Township <%= Html.DropDownList("Townships")%> 
     Range <%= Html.DropDownList("Ranges")%> 
     Section <%= Html.DropDownList("Sections")%> 

     <% Html.RenderPartial("Corners")%> 

     <input type="submit" value="Search" />   
     <span id="loader">Searching...</span> 
    <% End Using%> 
    <div id="searchResults"></div> 

</asp:Content> 
+0

Qual è l'html della vista parziale? – amurra

risposta

7

voglio dire un'opzione senza vedere il tuo PartialView è quello di avvolgere il PartialView in un div:

<div id="corners"><% Html.RenderPartial("Corners")%></div> 

Poi abbiamo il tuo ajax chiamata un'azione nel controller che restituirà un PartialViewResult e caricherà il risultato in quel div:

$.ajax({ 
      type: "GET", 
      url: "Search/Search?section=" + section + "&township=" + township + "&range=" + range, 
      dataType: "html", 
      success: function (result) { 
       $('#corners').html(result); 
      } 
     }); 
+1

Grazie mille per questo suggerimento. Ho fatto un piccolo ritocco e l'ho fatto funzionare. –

0

$ .ajax ({ tipo: "GET", url: "?/Ricerca/Ricerca section =" + sezione + "& township =" + township + "& gamma =" + gamma, dataType: "html ", success: function (result) { $ ('# corners'). Html (risultato); } });

Problemi correlati