Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda