1

I have a partial view that I need to fully refresh after an Ajax call. When I do, part of it is but not all of it. When I step through it to see what is being caught it looks like just the forms in the partial view are being refreshed and not other parts of it. Is there anything that could be causing this?

jQuery and Ajax that refreshes the view and view that contains other partial views:

<script type="text/javascript" charset="utf-8">
$(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);
    }
});
</script>

<section>
<div id ="ButtonsPartial" title="ButtonsPartial">
    @Html.Action("ButtonsPartial", "Home")
</div>
<div id="Partial_Chem_Analysis" title="Partial_Chem_Analysis">
    @Html.Action("PartialChemAnalysis", "Home", Model)
</div>
</section>
<section>

The partial view:

@using System.Data;
@using System.Dynamic;
@using System.Collections.Generic;
@using System.Linq;
@model TheManhattanProject.Models.ButtonsModel


<div id="Chem_Buttons">
<h2 class="alignleft">Chemistry Table</h2>
<p class="alignright">Heat Name<input type="text" name="heat_name" value="@Model.heatName" class="search-query" placeholder="Search" style ="width:100px" readonly="true"/>
<button class="btn btn-success" id="Change_Heat_Name" value="Change_Heat_Name" name="action:Change_Heat_Name" type="button"> Change Heat Name</button>
Grade<input type="text" name="heat_grade" value="@Model.grade" class="search-query" placeholder="Search" style="width:100px" readonly="true"/>
<button class="btn btn-success" id="ChangeHeatGrade" value="ChangeHeatGrade" name="action:Change_Grade" type="button">Change Grade</button>
Delete Record<input type="text" name="delete_record" value="@Model.heatName" class="search-query" placeholder="Search" style ="width:100px" readonly="true"/>
<button class="btn btn-success" id="DeleteRecord" value="DeleteRecord" name="action:Delete_Record" type="button">Delete Record</button>
  </p>
  <div style="clear: both;"></div>
  </div>
<div id="HeatNameDiv" title="Change Heat Name">
    @using (Html.BeginForm("ChangeHeatName", "Home", "POST"))
   {
    <section>
        Heat Name:<input type="text" name="heatName" value="@Model.heatName" style ="width:100px" readonly="true"/>
        //Value staying to what was entered not ""
        Change to:<input type="text" name="updatedHeat" value="" style="width: 100px" />
        <input type="button" id="ChangeHeatName" name="ChangeHeatName" value="Change" />
    </section>
}
</div>

<div id="HeatGradeDiv" title="Change Heat Grade">
@using (Html.BeginForm("ChangeGrade", "Home", "POST"))
{
    <section>
        Heat Grade:<input type="text" name="grade" value="@Model.grade" style ="width:100px" readonly="true"/>
        Change to:<input type="text" name="updatedGrade" value="" style="width: 100px" />
        <input type ="hidden" name="hiddenHeat" value ="@Model.heatName)" />
        <input type="button" id="ChangeGrade" name="ChangeGrade" value="Change" />
    </section>
}
</div>

<div id="DeleteRecordDiv" title="Delete Record">
@using (Html.BeginForm("DeleteRecord", "Home", "POST"))
{
<section>
    Heat Name:<input type="text" name="heatName" value="@Model.heatName" style ="width:100px" readonly="true"/>
    <input type="button" id="DeleteRecordBtn" name="DeleteRecordBtn" value="Delete" />
</section>
}
</div>
Danger_Fox
  • 449
  • 2
  • 11
  • 33

2 Answers2

1

From what I understand after your edits is the response from this bit of code is giving you problems.

$.ajax({
    type: "GET",
    url: '@Url.Action("ButtonsPartial","Home")',
    success: function (result2) { $("#ButtonsPartial").html(result2); }
});

A couple of things with this is

  1. You don't show a container with ButtonsPartial id. So if it doesn't exist it you can't display the result.
  2. It is using GET and that can be cached by your browser. With the browser debugger like firebug or developer tools you can see the response to the ajax call and see if it really is getting new data from your server.

Edit: I see your ButtonsPartial div now. So #1 isn't an issue.

Jasen
  • 14,030
  • 3
  • 51
  • 68
  • I've checked what it's getting back as a response and it's exactly what is in the partial view. The main issue that I can see is that what's in the "Change To:" field does not get reset. However when I look at the response it is set to "" like it should, it's just not reflecting that on the page. If that makes any sense. – Danger_Fox Apr 24 '13 at 18:21
  • When I look at the response in firebug, it's the HTML of the ButtonsPartial view as it should be rendered. – Danger_Fox Apr 24 '13 at 18:45
  • If you comment out `$("#Partial_Chem_Analysis").html(result);` does the `ButtonsPartial` load as you expect? – Jasen Apr 24 '13 at 19:10
  • If I do that it has the same results – Danger_Fox Apr 24 '13 at 19:23
0

You have no Partial_Chem_Analysis tag

forseta
  • 89
  • 4
  • It's contained within another view that's not relevant to the question. – Danger_Fox Apr 24 '13 at 17:54
  • @Jasen that view refreshes fine and does what it's supposed to. I'll update my question with that code so you can see. Also, I've updated the question because I marked the part that was not updating incorrectly – Danger_Fox Apr 24 '13 at 17:59