I had a Details view which it's contain a Save and AddLine button. The AddLines button will call javascript function "AddLinePopup" to open a new window ("window.open('./AddLine?id=' + id") with Add Line view. This was working correctly when open the Details view directly. The problem occurred when the Save button is clicked and it call to Controller (PRController) to save data and redirect back to Details view again. The URL in AddLinePopup javascript function will append the controller ("'PR/Details/AddLine?id=1") when AddLine button is clicked and causing the URL error. I did tried using "window.open('~/PR/AddLine?id=' + id')", "window.open('../PR/AddLine?id=' + id')" not working as well. How can I render the javascript AddLinePopup function URL correctly ("'PR/AddLine?id=1") after Save button is clicked? Any suggestion or solution is highly appreciated. Thanks in advance.
//PRController
public ActionResult Save(DetailsModel pr)
{
return RedirectToAction("Details", new { id = pr.ID });
}
//View
@using (Html.BeginForm("Save", "PR", FormMethod.Post))
{
<input type="submit" value="Save" class="btn btn-primary" title="Save changes" />
}
@Html.ActionLink("Line", "AddLine", null, new { @class = "fa fa-plus-square btn btn-primary",
title = "Add new line", onclick = "AddLinePopup('" + @Model.ID + "');return false;" })
<script type="text/javascript">
AddLinePopup = function (id) {window.open('./AddLine?id=' + id, "AddLineWindow", target = '_blank','width=800px,height=650px,top=10,left=250');
}
</script>