Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
MVC URL in Javascript Not Render Correctly

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>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This solve my problem. I use link to call Javascript function and open new window in JavaScript.

`<a href="javascript:AddLinePopup('@Url.Action("AddLine", "PR")','@Model..ID')">

AddLinePopup = function (url,id) { window.open(url + '?id=' +id,"addlineWindow",'width=800px,height=400px,top=10,left=e250');}`

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!