I'm working with a fairly common pattern - a page opens a child window (a popup) where a form permits the user to edit information (create new User Account). The controller validates the popup's submission and either tosses error messages or commits the update. If the update _is committed the user has no further need for the popup.
I need to add code to the cont开发者_StackOverflow中文版roller that 1) fires a javascript function on the popup (self.close();) and 2) returns a value to the parent window. (user was created...the new user's ID = foo)
You can have the window post the data to a controller action that can return a JsonResult indicating that the user's been successfully committed.
Before you call self.close() on the popup, you can address the popup's parent through opener - either expose a public function or a public property on the page that fires the popup and the child can set a value in it. If you have a function exposed, it'll be cleaner to have the page update itself to let the user continue on.
Quick way to do this is to create a success view which is returned if the creation of the user is successful.
This view can take in the newly created user and have the required JavaScript to pass the data back to the parent window and close the popup. You can then inject the users Id into the JavaScript in the View code.
精彩评论