views:

434

answers:

2

Hi all,

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

A: 

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.

Wil
entered the code in here by accident
Paul GRiffin
A: 

Hi Will, thanks for your response ... yes your right of course i should have specified submit rather than postback! I'm a converted asp.net head so still stuck in that mindset!

I think i get the idea, just not sure how to go about it, specifically how to i set the content of a div from an ajax request?

was trying something liek this:

 var URL = '<%= ResolveUrl("~") %>/ImagePicker/Index/0/283';
        $.get(URL, function(data) {
            $("#Result").html(data);
        }); 

<div id="Result"></div>
Paul GRiffin
You should have left it as a comment to my answer :) Generally on StackOverflow, answers should just be answers.Anyways, in your example, in the action what are you returning?
Wil