Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Dialog box holding data after partial view refresh
    text
    copied!<p>I have a partial view that opens a dialog box for entering some data. Once the button is clicked, an Ajax call is performed to reset that partial view and another. When I step through the code, everything seems to work alright except that when I open the partial view back up it the data is still in the box. I found some success following this question <a href="https://stackoverflow.com/questions/11528196/caching-issue-with-loading-partial-views-into-jquery-dialogs">Caching issue with loading partial views into JQuery dialogs</a> but when I implement that the button doesn't work the second time I use it. My code is below:</p> <p>jQuery and Ajax that refreshes the view and view that contains other partial views:</p> <pre><code>&lt;script type="text/javascript" charset="utf-8"&gt; $(document).ready(function () { $('#ChangeHeatName').click(function (e) { var tdata = $('#form1').serialize(); var origname = $('#HeatNameDiv').find('input[name="heatName"]').first().val(); var newname = $('#HeatNameDiv').find('input[name="updatedHeat"]').first().val(); $.ajax({ type: "POST", data: { mCollection: tdata, heatName: origname, updatedHeat: newname }, url: '@Url.Action("ChangeHeatName","Home")', //url: "/Home/ChangeHeatName", success: function (result) { success(result); } }); }); function success(result) { $('#HeatNameDiv').dialog('close'); //Ajax with problem $.ajax({ type: "GET", url: '@Url.Action("ButtonsPartial","Home")', success: function (result2) { $("#ButtonsPartial").html(result2); } }); $("#Partial_Chem_Analysis").html(result); } }); &lt;/script&gt; &lt;section&gt; &lt;div id ="ButtonsPartial" title="ButtonsPartial"&gt; @Html.Action("ButtonsPartial", "Home") &lt;/div&gt; &lt;div id="Partial_Chem_Analysis" title="Partial_Chem_Analysis"&gt; @Html.Action("PartialChemAnalysis", "Home", Model) &lt;/div&gt; &lt;/section&gt; &lt;section&gt; </code></pre> <p>The partial view:</p> <pre><code>@using System.Data; @using System.Dynamic; @using System.Collections.Generic; @using System.Linq; @model TheManhattanProject.Models.ButtonsModel &lt;div id="Chem_Buttons"&gt; &lt;h2 class="alignleft"&gt;Chemistry Table&lt;/h2&gt; &lt;p class="alignright"&gt;Heat Name&lt;input type="text" name="heat_name" value="@Model.heatName" class="search-query" placeholder="Search" style ="width:100px" readonly="true"/&gt; &lt;button class="btn btn-success" id="Change_Heat_Name" value="Change_Heat_Name" name="action:Change_Heat_Name" type="button"&gt; Change Heat Name&lt;/button&gt; Grade&lt;input type="text" name="heat_grade" value="@Model.grade" class="search-query" placeholder="Search" style="width:100px" readonly="true"/&gt; &lt;button class="btn btn-success" id="ChangeHeatGrade" value="ChangeHeatGrade" name="action:Change_Grade" type="button"&gt;Change Grade&lt;/button&gt; Delete Record&lt;input type="text" name="delete_record" value="@Model.heatName" class="search-query" placeholder="Search" style ="width:100px" readonly="true"/&gt; &lt;button class="btn btn-success" id="DeleteRecord" value="DeleteRecord" name="action:Delete_Record" type="button"&gt;Delete Record&lt;/button&gt; &lt;/p&gt; &lt;div style="clear: both;"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="HeatNameDiv" title="Change Heat Name"&gt; @using (Html.BeginForm("ChangeHeatName", "Home", "POST")) { &lt;section&gt; Heat Name:&lt;input type="text" name="heatName" value="@Model.heatName" style ="width:100px" readonly="true"/&gt; //Value staying to what was entered not "" Change to:&lt;input type="text" name="updatedHeat" value="" style="width: 100px" /&gt; &lt;input type="button" id="ChangeHeatName" name="ChangeHeatName" value="Change" /&gt; &lt;/section&gt; } &lt;/div&gt; &lt;div id="HeatGradeDiv" title="Change Heat Grade"&gt; @using (Html.BeginForm("ChangeGrade", "Home", "POST")) { &lt;section&gt; Heat Grade:&lt;input type="text" name="grade" value="@Model.grade" style ="width:100px" readonly="true"/&gt; Change to:&lt;input type="text" name="updatedGrade" value="" style="width: 100px" /&gt; &lt;input type ="hidden" name="hiddenHeat" value ="@Model.heatName)" /&gt; &lt;input type="button" id="ChangeGrade" name="ChangeGrade" value="Change" /&gt; &lt;/section&gt; } &lt;/div&gt; &lt;div id="DeleteRecordDiv" title="Delete Record"&gt; @using (Html.BeginForm("DeleteRecord", "Home", "POST")) { &lt;section&gt; Heat Name:&lt;input type="text" name="heatName" value="@Model.heatName" style ="width:100px" readonly="true"/&gt; &lt;input type="button" id="DeleteRecordBtn" name="DeleteRecordBtn" value="Delete" /&gt; &lt;/section&gt; } &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload