gpt4 book ai didi

javascript - MVC4,使用 jQuery 在对话框中呈现局部 View ,如何刷新

转载 作者:行者123 更新时间:2023-11-30 06:25:29 25 4
gpt4 key购买 nike

我有一个局部 View ,它在一个对话框中弹出,代码如下。但是,在用户保存局部 View 后,当我再次单击 ActionLink 时,数据不会在该局部 View 中刷新,直到我停止调试并重新启动应用程序。但是,新记录在我的数据库中。另一个问题是当我重新启动应用程序时,由于以下错误,我无法更新记录。我错过了什么?谢谢。

    An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.

我的 View 中的div标签

    <div id="assign-dialog"></div>

同一 View 中的 ActionLink

    @Html.ActionLink("Assign", "Edit", "Assignment", new { id = Model.InfoId}, new { @class = "assign-modal" })

jQuery

    $(function () {

$(function () {
$('#assign-dialog').dialog({
autoOpen: false,
width: 400,
height: 500,
resizable: true,
modal: true
});

$('.assign-modal').click(function () {
$('#assign-dialog').load(this.href, function () {
$(this).dialog('open');
});
return false;
});

});

HTTP GET 操作

    [HttpGet]
[Authorize(Roles="Admin")]
public ActionResult ViewAssignment(int id = 0)
{
RequestAssignment query = _assignmentRepository.GetCurrentAssignment(id);

return PartialView("_ViewAssignment", query)
}

更新:

我最初是按照 javascript/jquery modal popup dialog MVC 4 / render partial view 中的步骤操作的在 Jasen 的回答的动态部分下,但不知道在“Client Partial,暂时为空”中放什么

...好吧,我已经阅读了一些其他帖子,这是我能够想出的,但是当我点击我的链接时没有任何反应。

查看html

    <a href="#" class="dialog-trigger" data-infoId="@Model.InfoId">Assign</a>
<div id="assign-modal">

</div>

jQuery

    //Dialog Box for Assignments
$(".dialog-trigger").on("click", function(event) {
event.preventDefault();
var infoId= $(this).data("infoId");
$.ajax({
url: "RequestAssignment/Edit/" + infoId,
type: "GET"
})
.done(function(result) {
$("#assign-modal").html(result).dialog("open");
});
});

最佳答案

所以经过长时间的搜索,我决定使用 Ajax.ActionLink。我知道有更好的方法,但这个方法对我有用。我要感谢@MattBodily 一路提供的所有帮助。

    @Ajax.ActionLink("Approve", "QuickAssign", "Assignment", new { id = Model.InfoId}, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace, OnSuccess = "openDialog" })

然后是我的 javascript 函数

function openDialog() {

//set the diaglog properties
$("#result").dialog({
title: 'Assign',
width: 550,
height: 'auto',
modal: true
});


$("#result").dialog("open");
}

关于javascript - MVC4,使用 jQuery 在对话框中呈现局部 View ,如何刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21440438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com