Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda