部分视图在Ajax调用后没有完全重新渲染
本文关键字:新渲染 视图 Ajax 调用 | 更新日期: 2023-09-27 18:10:40
我有一个需要在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>
根据我的理解,在您的编辑之后,这段代码的响应会给您带来问题。
$.ajax({
type: "GET",
url: '@Url.Action("ButtonsPartial","Home")',
success: function (result2) { $("#ButtonsPartial").html(result2); }
});
- 您没有显示
ButtonsPartial
id的容器。所以如果它不存在,你就不能显示结果。 - 它正在使用GET,可以被浏览器缓存。使用浏览器调试器,如firebug或开发人员工具,您可以查看对ajax调用的响应,并查看它是否真的从服务器获取新数据。
编辑:我现在看到你的ButtonsPartial
div。所以#1不是问题。
您没有Partial_Chem_Analysis标签