Close modal window containing ASP MVC Ajax form

前端 未结 1 1037
逝去的感伤
逝去的感伤 2021-02-06 14:40

in a webapp I\'m using an ASP MVC Ajax form in a modal window. I do not use any specific jQuery code, only some to open the modal window (i.e. showModal() function):

<         


        
1条回答
  •  臣服心动
    2021-02-06 15:04

    I just had to do the same thing today. The solution I came up with was to return a JsonResult with a property set to true when the action succeeded. In the OnSuccess callback of the AjaxOptions I checked for the property and closed my modal window.

    Controller Method

    [HttpPost]
    public ActionResult Hold(JobStatusNoteViewModel model)
    {
        if (ModelState.IsValid)
        {
            //do work
            return Json(new {success = true});
        }
    
        return PartialView("JobStatusNote", model);
     }
    

    PartialView

    <% using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "JobStatusForm", OnSuccess = "closePopUp" })) { %>
    
    <% } %>

    0 讨论(0)
提交回复
热议问题