Jquery – ASP.NET MVC Postback on Modal Dialog/ Popup

asp.net-mvcjquerymodal-dialogpopup

I have a link on an asp.net mvc view which opens a modal popup in which a second MVC view is rendered.

The view in the Modal popup exposes several features which trigger a postback. The postbacks fire the correct controller methods but when i return the updated view the View itself is render as opposed to being rendered in the modal popup.

That is the popup is closed , i am no longer on the 1st "parent page" instead the standalone url to the view in the modal popup is loaded.

What i would like to achieve is that a postback in the view in the modal popup loads the updated view back into the modal window?

Can anyone help?

I've seen references to partial views and ajax calls but not sure how they best fit in?

Thanks,
Griff

Best Answer

First off, MVC doesn't postback, it just does regular submits. May seem like semantics, but there is a fundamental difference.

To answer your question, if you want to update the modal window you have to go the ajax route. What you want to do is send the request via ajax and receive the response, then update some divs inside the modal window.

You can also perform a hack by referencing some property of the model you are passing into the view so that based on the model, you can render the correct partial view and then dynamically trigger the modal window trigger at the end of the view.