简体   繁体   English

mvc 5 RedirectToAction不返回视图,而是停留在同一浏览器页面上

[英]mvc 5 RedirectToAction does not return View, stays on the same browser page

I stumbled on an error when I tried to redirect a user to another view here: 当我尝试将用户重定向到另一个视图时,我偶然发现了一个错误:

public IActionResult Edit([FromBody]int id)
{
    return RedirectToAction("EditProduct", "Admin", new { id = id});
}

After that the view should be generated: 之后,应生成视图:

public IActionResult EditProduct(int? id)
{
    var Products = _repository.GetProduct(id);

    return View(Products);
}

In result the redirect gets into EditProduct View but in the browser it stays in the same page. 结果,重定向进入EditProduct View,但在浏览器中,它保留在同一页面中。 Am I doing something wrong or is there an exception I do not know about? 我是在做错什么,还是有我不知道的例外?

As Suman Pathak said in comments MVC does not do redirects using an ajax call. 正如Suman Pathak在评论中所说,MVC不会使用ajax调用进行重定向。 So i passed identificator via js file: 所以我通过js文件传递了identifier:

 window.location = "/Admin/EditProduct/" + productId;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM