Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC 3 Controller Action and Open New Window

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

like image 566
ntep vodka Avatar asked Oct 17 '11 07:10

ntep vodka


1 Answers

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.

like image 124
Matt Tew Avatar answered Oct 17 '22 13:10

Matt Tew