How do i open an URL in a new tab / window from MVC controller based on success condition .Any way i can achieve it through the help of c# code without having to write javascript ?
This cannot be done from the controller , but rather from your razor View:
@Html.ActionLink("linkText", "Action", new {controller="ControllerName"}, new {target="_blank"})
Calling URL from Controller:
return RedirectToAction("Edit", "Home");
Calling Action Method from View using HTML Button or Image:
When creating a link to a controller action in ASP.NET MVC, using the generic ActionLink method is preferable, because it allows for strongly typed links that are refactoring friendly.
@Html.ActionLink("Edit", "Home", new { id = item.ID })
However, what if we want to have an image that links to an action? You might think that you could combine the ActionLink and Image and Button helpers like this:
Using Button:
<button onclick="location.href='@Url.Action("Edit", "Home",new { Model.ID })';return false;">Detail</button>
<input type="button" title="Delete" value="D" onclick="location.href='@Url.Action("Edit", "Home", new { id = item.ID })'" />
Using Image:
<a href="@Url.Action("Edit", "Home", new { id = item.ID })" title="Edit">
Hope this helps...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With