JavaScript函数在执行MVC 5后重定向到索引页

JavaScript函数在执行MVC 5后重定向到索引页,javascript,asp.net-mvc,Javascript,Asp.net Mvc,我正在通过调用函数 @Html.ActionLink("Edit", "", null, new { onclick = "editshow('"+ item.vend_id + "','" + item.vend_name + "','" + item.vend_addr + "','" + item.vend_pno + "');" }) 剧本是 <script type="text/javascript"> function editshow(i, n, a, p) {

我正在通过调用函数

@Html.ActionLink("Edit", "", null, new { onclick = "editshow('"+ item.vend_id + "','" + item.vend_name + "','" + item.vend_addr + "','" + item.vend_pno + "');" })
剧本是

<script type="text/javascript">
function editshow(i, n, a, p) {
    document.getElementById("vid").value = i;
    document.getElementById("vnam").value = n;
    document.getElementById("vad").value = a;
    document.getElementById("vpno").value = p;


}

函数editshow(i,n,a,p){
document.getElementById(“vid”).value=i;
document.getElementById(“vnam”).value=n;
document.getElementById(“vad”).value=a;
document.getElementById(“vpno”).value=p;
}


执行后,它总是重定向到索引页。如何阻止它?

我假设您故意将
操作
名称留空

因为您不想在单击时点击服务器,所以应该从javascript函数返回false

    function editshow(i, n, a, p) {
      document.getElementById("vid").value = i;
      document.getElementById("vnam").value = n;
      document.getElementById("vad").value = a;
      document.getElementById("vpno").value = p;

      return false;
   }

如果未从按钮单击处理程序返回
false
,则很可能会导致
postback
行为。在这种情况下,它将找到默认页面,在您的情况下,它可能是
index.cshtml

Hi Billalcheema,正如这里的评论中所讨论的,这是答案

 function editshow(i, n, a, p) {
      document.getElementById("vid").value = i;
      document.getElementById("vnam").value = n;
      document.getElementById("vad").value = a;
      document.getElementById("vpno").value = p;

    window.location.href = '@Url.Action("Edit", "Home")';
   }

是的,这正是我想要做的,不管你的解决方案如何尝试。仍在重定向。@Bilalwcheema查看浏览器的开发人员控制台。您可能有一个连接错误,这也可能导致一个空白的回发尝试,不使用@Html.ActionLink,只需使用onclick添加一个简单的按钮/afunction@Bilalwcheema在我看来,您可以使用window.location.href='@Url.action(“Edit”,“Home”)”;,重定向到所需的任何操作。因此,也可以通过这种方式避免重定向到索引页。希望能有帮助。thanks@KarthikElumalai你会写吗?