I have a page which open a new window with External Url (Twitter Authentication Url) now that window will authenticate the user and call back to an action method , in that action method i have to close the current window (popUp) and inform the opener that authentication succeeded,
in web forms i used to do something like this on a (postback):
(HttpContext.Current.Handler as System.Web.UI.Page).ClientScript.RegisterStartupScript(
this.GetType(),
"winPop",
"window.opener.doSomething(true);window.close()",
true);
in MVC i tried this but didnt work since there is no Current but there is :
HttpContext.CurrentHandler
which can be casted to Mvc.MvcHandler now the question arise i know MVC is totally Different but is there is any way to register script which would run at the response startup ?
I know i can make an extra view and open it in the new window and then redirect to Twitter Url and then on the call back to the same Window i would call the script simply window.opener……etc but that would mean i have to make an extra view that only have nothing but a line of javascript at the startup, so i was wondering if i can do one of the following :
Option 1: Register Start up Script like i explained above.
Option 2: Return javascript code that runs at the client (no actual view).
You can simply forget what you were doing classic WebForms as it won’t be of much of a help in ASP.NET MVC.
In ASP.NET MVC you have Models, Controllers and Views (as its name suggests). So if you wanted to call a javascript function in your view and pass it some value from your model you could do the following:
where obviously your controller action will populate this model and pass it to the view:
and of course a corresponding model:
See? Model, View, Controller.
UPDATE:
You don’t need a model in this simple case:
and inside
CallbackAction.cshtml: