2017-08-05 11 views
0

保存ボタンをクリックしてDialog Ajaxフォームを投稿した後、ダイアログを閉じて元のページに戻ることができません。MVCでJsonResponseが成功した後にダイアログを閉じる方法

代わりに、私は新しいページに表示されたJson応答を得ています。

は、私が何かをしないのですが、私のコードはIndex.cshtml

<div id="dialog-model" title="Basic Model Dialog"> 
</div> 

<script> 
    $(function() { 
     $("#dialog-model").dialog({ 
      autoOpen: false, 
      width: 900, 
      height: 450, 
      show: { 
       effect: "blind", 
       duration: 1000, 
      }, 
      hide: { 
       effect: "blind", 
       duration: 1000, 

      } 
     }); 
    }); 

    function editAccount(accountId) { 
     $("#dialog-model").dialog("open"); 
     $.ajax({ 
      url: '/Account/Edit', 
      contentType: 'application/html', 
      data: {id: accountId}, 
      success: function(content) { 
       $('#dialog-model').html(content); 
      }, 
      error: function(e) {} 
     }); 
    }; 
    function updateSuccess(data) { 
     alert(data); 
    } 
</script> 

AccountController.cs

ある

を見てどこかわからない知っている

// GET: Account Edit 
public ActionResult Edit(int id) 
{ 
    var account = _accountService.GetAccountById(id); 

    return PartialView(account == null ? new AccountDetailsModel(new Account()) : new AccountDetailsModel(account)); 
} 

// POST: Account Edit 
[HttpPost] 
public ActionResult Edit(AccountDetailsModel accountDetailsModel) 
{ 
    if (ModelState.IsValid) 
    { 
     //return RedirectToAction("Index"); 
     return Json(new { success = true, responseText = "The attached file is not supported." }, JsonRequestBehavior.AllowGet); 
    } 
    else 
    { 
     return Json(new { success = false, responseText = "The attached file is not supported." }, JsonRequestBehavior.AllowGet); 
    } 
} 

Edit.cshtml

@model BusinessOracle.Web.Models.Accounts.AccountDetailsModel 


@using (Ajax.BeginForm("Edit", "Account", new AjaxOptions 
{ 
    InsertionMode = InsertionMode.Replace, 
    HttpMethod = "POST", 
    OnSuccess = "updateSuccess" 
}, new { @id = "edit-account-form" })) 
{ 
    @Html.ValidationSummary(true) 
    <div id="update-message" class="error invisible"></div> 
    <fieldset> 
     <legend>Edit Account</legend> 

     @Html.HiddenFor(model => model.Id) 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Code) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Code) 
      @Html.ValidationMessageFor(model => model.Code) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Name) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Name) 
      @Html.ValidationMessageFor(model => model.Name) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Description) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Description) 
      @Html.ValidationMessageFor(model => model.Description) 
     </div> 

     <p> 
      <input type="submit" value="Save" /> 
     </p> 
    </fieldset> 
} 

答えて

0

は、私が行方不明になったことを発見し

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script> 
関連する問題