我正在使用 MVC C# 和 Jquery。我有一个局部视图,每次用户从视图中修改某些数据时都需要更新它。问题是部分视图没有更新。如何更新局部视图?
部分视图中的 jquery 代码 (WorkReport)
$("#modify").click(function () {
var duration = $("#newDuration").val();
var date_param = $("#dateParam").val();
$.ajax({
url: '@Url.Action("ModifyDuration", "ViewWork")',
type: 'post',
data: { newDuration: duration, id: psm_id, date: date_param },
dataType: 'text',
traditional: true,
beforeSend: function (jqXHR, settings) {
$.mobile.showPageLoadingMsg();
},
success: function (data) {
$("#workList").html(data).trigger('create');
$.mobile.hidePageLoadingMsg();
},
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
}
}
});
});
控制器代码:
[HttpGet]
public PartialViewResult GetWorkList(string date)
{
model.workList = workList;
return PartialView("WorkReport", model);
}
[HttpPost]
public ActionResult ModifyDuration(string newDuration, string id, string date)
{
DataOperation dataOperation = new DataOperation();
dataOperation.UpdateWorkDuration(newDuration, id);
return RedirectToAction("GetWorkList", new
{
date = date
});
}