---
title: "JQuery Dialog box not closed in ASP.NET MVC 4"  
description: "JQuery Dialog box not closed in ASP.NET MVC 4"  
author: "Takeshi Okada"  
published: 2013-01-30  
updated: 2013-01-30  
canonical: https://www.mindstick.com/forum/562/jquery-dialog-box-not-closed-in-asp-dot-net-mvc-4  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# JQuery Dialog box not closed in ASP.NET MVC 4

Hi Everyone!

I am using a [dialog box](https://www.mindstick.com/forum/34699/create-alert-dialog-box-in-android) with [jQuery in MVC](https://www.mindstick.com/forum/34333/how-i-can-call-a-model-popup-with-data-by-using-jquery-in-mvc) 4, my code as below

<div id="dialogBox" title="Select [Products](https://www.mindstick.com/news/2358/apple-will-use-us-made-semiconductors-in-its-products-to-lessen-its-dependency-on-asia)" style="[overflow](https://www.mindstick.com/interview/1711/what-is-overflow-properties-in-css): hidden;">\
</div>

\
$('#dialogBox').load("@[Url.Action](https://www.mindstick.com/forum/12700/passing-arguments-to-url-action)("SelectProducts")",\
[function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server)([response](https://www.mindstick.com/forum/12719/how-to-make-response-write-display-special-character-like-lt-gt), status, xhr) {\
$('#dialogBox').dialog('open');\
});

When I clicks on [submit button](https://www.mindstick.com/forum/12834/make-text-appear-when-submit-button-clicked-and-checkbox-is-unchecked) in the dialog box I got to httppost as such

\
[HttpPost]\
public [ActionResult](https://www.mindstick.com/forum/33961/what-is-the-difference-between-actionresult-and-viewresult) SelectProducts(Products model)\
{\
if ([ModelState.IsValid](https://www.mindstick.com/forum/2002/modelstate-isvalid-contains-errors-when-using-mongodb))\
{\
lbService.ProductsData(model);\
return View(model); // success \
}

return View(model); // problem

}

Thanks in advance

## Replies

### Reply by AVADHESH PATEL

Hi Takeshi Okada!

Used an Ajax.BeginForm inside the partial that you are loading and put the contents that you want to be loaded in the dialog inside a partial and also have your HttpPost controller action return this same partial view instead of returning an entire view.

Include the jquery.unobtrusive-ajax.js script to your page for Ajax.BeginForm form to work.\
As an alternative to using Ajax.BeginForm you could still use a normal Html.BeginForm and manually AJAXify it:\

```
$(document).on('submit', '#dialogBox form', function() {    $.ajax({        url: this.action,        type: this.method,        data: $(this).serialize(),        success: function(result) {            if (result.success) {                $('#dialogBox').dialog('close');            } else {                $('#dialogBox').html(result);            }        }      });    return false;});
```


---

Original Source: https://www.mindstick.com/forum/562/jquery-dialog-box-not-closed-in-asp-dot-net-mvc-4

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
