ASP.Net MVC 3 Controller Action and Open New Window
18,287
Technically, this can be done by returning javascript that will open the new window.
However, most browsers will kill a new window called in this manner (i.e. popup blocker).
You would be better off, if possible, by opening the link to your action in a new window from the start;
@Html.ActionLink("New report", "New", "Report", null, new {target = "_blank"})
Edit
I can see from your action, that it is probably a form that creates the report; you can also use the attribute target='_blank'
on a form as well.
Author by
ntep vodka
Updated on June 04, 2022Comments
-
ntep vodka almost 2 years
i have a controller and an action. this action is to save data into database. and now, i want when i submit a button, my controller do an action and open new window.
public ActionResult New(FormCollection collection) { data.Population_Code = collection["Countrys[0].CountryCode"]; data.Population_Desc = collection["Countrys[0].CountryDesc"]; data.Population_Grouping = collection["Countrys[0].CountryGroup"]; data.Population_Type = "CNTRY"; data.Population_Redudant = "N"; data.Population_Modified_At = officeCode.User_Office.ToString(); db.SaveChanges(); //example for new window //window.open('/Report/New.aspx') return RedirectToAction("index"); }
so my controller do an action and open a new window.
anyone can help me ?
thanks
-
ntep vodka over 12 yearsthanks Matt, yeah this is for showing report. actually, i have menu report. but now my boss tell me to do something like, whenever the controller do New action it will show report in a new window. and now, i got confused how to get the value that i added. see edit
-
Matt Tew over 12 yearsYes, you could use the actionlink sample to create your menu link. This just opens the new window before calling the action, which can then save the data and open up the report view.