Danger_Fox
Danger_Fox

Reputation: 449

Partial View not being fully re-rendered after Ajax call

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>

Upvotes: 1

Views: 3424

Answers (2)

Jasen
Jasen

Reputation: 14250

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.

Upvotes: 1

forseta
forseta

Reputation: 89

You have no Partial_Chem_Analysis tag

Upvotes: 0

Related Questions