在Ajax调用之后,部分视图未完全重新呈现

时间:2013-04-24 17:19:46

标签: c# jquery ajax asp.net-mvc

我有一个局部视图,我需要在Ajax调用后完全刷新。当我这样做时,其中一部分却不是全部。当我单步执行它以查看正在捕获的内容时,看起来只是部分视图中的表单正在刷新而不是其他部分。有什么可能导致这个吗?

jQuery和Ajax刷新包含其他部分视图的视图和视图:

<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>

部分视图:

@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>

2 个答案:

答案 0 :(得分:1)

根据我的理解,您编辑后的代码响应会给您带来问题。

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

有几个问题是

  1. 您不会显示ID为ButtonsPartial的容器。因此,如果它不存在,则无法显示结果。
  2. 它正在使用GET,您可以通过浏览器进行缓存。使用像firebug或开发人员工具这样的浏览器调试器,您可以看到对ajax调用的响应,看看它是否真的从您的服务器获取新数据。
  3. 修改:我现在看到你的ButtonsPartial div了。所以#1不是问题。

答案 1 :(得分:0)

您没有Partial_Chem_Analysis标记