This is a migrated thread and some comments may be shown as answers.

[Solved] How to post from a window to a controller and keep the window open?

1 Answer 136 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul Hoeffer
Top achievements
Rank 1
Paul Hoeffer asked on 08 Dec 2010, 10:43 PM

It's not clear to me how to handle an MVC form update in the Window and have the results returned to the and not the supporting page. 

In my MVC2 application, one of of the views I want a modal window to update some related data. So on the view I declare my window like this:

 

<% Html.Telerik().Window()
       .Name("Window")
       .Title("Title of New Window")
       .Draggable(true)
       .Modal(true)
       .Buttons(b => b.Close())
       .LoadContentFrom("/Controller/Action")
       .Width(400)
       .Height(105)
       .Visible(false)
       .Render();
%>

 

 

Thus I have a window ready to be opened.  When the user clicks on a button on a row of a grid on the view, I open the window using this code

<div class="t-grid-action t-button t-state-default" onclick="openWindow(
'<%: ViewData["Property1"] %>', 
'<%: Model.Property2 %>');">
Add
</div>

The js function is pretty simple too:

function openWindow(parm1, parm2) {
    var window = $("#Window").data("tWindow");
    var url = "/Controller/Action2?parm1=" + parm1 + "&parm2=" + parm2;
    window.ajaxRequest(url);
    window.center();
    window.open();
}

Action2 is HttpGet and returns a view based on a strongly typed model.  So far, so good.  Now, when the view *posts* back to the controller 

<% using (Html.BeginForm("Action2", "Controller", RouteObject, FormMethod.Post)) {%>

And in the controller Action2 has a different method for HttpPost, which updates the model, etc.  However when I return the view instead of just the Window being updated and staying modal (so the user can correct the form), what happens instead is that the entire browser window is updated, not the modal window.

What am I doing wrong?  I'd expect just the modal would be updated, not the entire browser.

1 Answer, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 10 Dec 2010, 09:54 AM
Hi Paul,

The solution Alex suggested to you in this forum thread shows how to submit the form. Updating the content of the window with the returned response can be done in the success callback:

$.post(this.action, data, function(response){
    $('#feedback-form').closest('.t-window-content').html(response);
});

Greetings,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Window
Asked by
Paul Hoeffer
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Share this question
or