I have one [post] action which return Redirect(url). I want to open this response in new tab.
I have one [post] action which return Redirect(url). I want to open this response in new tab.
Is it mandatory to use javascript? :
@using (Html.BeginForm("Action","Controller",FormMethod.Post, new { target = "_blank" }))
{
<input type="submit" value="clickme"/>
}
Html:
@using (Html.BeginForm("Action", "Controller", FormMethod.Post))
{
<button id="aButton" >Submit</button>
}
Javascript using jQuery:
$('#aButton').click(function (event) {
event.preventDefault();
var form = $(this).parent('form');
form.attr('target', '_blank');
form.submit();
});
This way you can leave your action as is and if you want to submit other form variables you can if you include them within your form.
The above solution is unobtrusive and works if javascript is disabled.