RedirectToAction htmlAttribute overload

2019-08-14 20:36发布

问题:

I want to open a RedirectToAction in a new tab. Unfortuantely there is no overload that takes a htmlAttribute as with ActionLink

@Html.ActionLink("Text", "Action", new { parameters }, new { target="_blank" })

Is it possible to write an overload for RedirectToAction to do this from the Action. If so would you please post the working code for the overload.

I want to open the new tab programatically from the Action, not a link that has to be clicked. So please no answers on how to do it with an actionlink. I already stated I know how to do that.

Thanks,

Joe

回答1:

unfortunately there is no mechanism server side to open a new tab/window. This has to be done client side. The server is simply sending back an http response to the browser, and there is no special message in the http protocol to open a new tab/window. Somebody wrote a workaround for ASP.NET that basically executes a client side script after the redirect, you can take a look here