簡體   English   中英

MVC4,使用jQuery在對話框中渲染部分視圖,如何刷新

[英]MVC4, Render Partial View in Dialog Box with jQuery, How to refresh

我有一個局部視圖,該對話框在帶有以下代碼的對話框中彈出。 但是,在用戶保存部分視圖之后,當我再次單擊ActionLink之前,直到停止調試並重新啟動應用程序之前,數據不會在該部分視圖中刷新。 但是,新記錄在我的數據庫中。 另一個問題是,當我重新啟動應用程序時,由於以下錯誤,我無法更新記錄。 我想念什么? 謝謝。

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

我的視圖中的div標簽

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

同一視圖中的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模態彈出對話框MVC 4中的步驟/在Jasen的答案的動態部分下呈現部分視圖 ,但不知道要在“客戶端部分,現在為空”中添加什么

...好吧,所以從其他一些文章中我讀到了這就是我能想到的內容,但是當我單擊鏈接時什么也沒有發生。

查看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");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM