1

in my view I have simple table with link to product:

<td>@Html.ActionLink("View details", "Open","Home",new { id = product.Id, url = product.Url })</td>

In my controller, I am doing some stuff with received data:

public ActionResult Open(int id, string url)
{
    productService.AddUserVisit(id);
    return RedirectToAction("Index");
}

And after all I am refreshing page. What I want to do is to open passed url in next page. How can I do that?

dafie
  • 951
  • 7
  • 25
  • Can you elaborate a bit more on your flow, because based on what I see you pass to an action to simply execute the same `Get` within your controller. Not a separate controller and action. – Greg Apr 03 '19 at 22:43

2 Answers2

1

Can you just use

return Redirect(url)

Or if you need to go to the Index page first for some reason, you could try

return RedirectToAction("Index", new { url = url });

and obviously accept the url as a string on your index controller.

Hope that helps

Mark

Mark
  • 69
  • 10
0

I believe you want something similar to this question here: Redirect to external URI from ASP.NET MVC controller

Except you want to do this:

return Redirect(url);
Murchiad
  • 103
  • 10
  • I want to refresh current page, and open another page in another tab. What's more I cant use it in my code. I am getting `Server Error in '/' Application.` – dafie Apr 03 '19 at 22:48
  • Sounds like this should happen in javascript on the page. You can use window.open() documentation here: https://www.w3schools.com/jsref/met_win_open.asp and the function to reload page: location.reload(); – Murchiad Apr 03 '19 at 22:50