2

I am still a bit of a fresher with MVC post backs from the ajax call but I will show what I have (laymenised) and im hoping someone can point me in the direction of getting the response open in a new browser tab.

I am passing my MVC Controller and Action in the sourceURL below:

$j.ajax({
          url: sourceURL,
          cache: false,
          type: 'get',
          success: function (data, statusText, jqXHR) {
              // Do stuff here
          }
});

which takes me to my Controller Action:

        public ActionResult Edit(bool isForPartial = false, int actionId = 0, int objectId = 0, int parentObjectId = 0, string parentObjectType = "", bool fullView = false)
        {
           // Do Stuff Here aswell
           return RedirectToAction(actionName, controllerName, new {params...})
        }

The Action on the return is called and a Partial View is loaded. I, however, would like this page to be opened on a new browser tab.

I am hoping there is something simple I can do from the ajax call to make this happen but I know life isn't generally that easy so any help on this is appreciated!

CJH
  • 1,266
  • 2
  • 27
  • 61
  • this `actionName` to which you redirect... is it return some partial view or what? – demo Apr 17 '18 at 21:27
  • Good Question.... After some convoluted processing it finally gets round to returning a Partial View. – CJH Apr 17 '18 at 21:40

3 Answers3

1
you can call action method something like below
<a href="@Url.Action("Action", "Controller")" target="_blank">Link Text</a>
@Html.ActionLink("linkText", "Action", new {controller="Controller"}, new {target="_blank"})
0

Have not worked with asp.net so don't know for sure what RedirectToAction(actionName, controllerName, new {params...}) returns, but if what you need is to open a new tab with the server's response, you could return that new url in your controller action and get it in ajax via the data param in the success function, there you can do:

window.open(data);

see here

HIH

Scaramouche
  • 3,188
  • 2
  • 20
  • 46
0

On Success of your ajax call use this code to open the new window and do your work in controller of mvc

     window.open(
    "Controller/Action?args=" + encodeURIComponent(val),
    "_blank");