【问题标题】:mvc 5 RedirectToAction does not return View, stays on the same browser pagemvc 5 RedirectToAction 不返回视图,停留在同一浏览器页面上
【发布时间】:2016-06-01 10:03:42
【问题描述】:

当我尝试将用户重定向到此处的另一个视图时,我偶然发现了一个错误:

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

之后应该生成视图:

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

    return View(Products);
}

结果重定向进入 EditProduct 视图,但在浏览器中它停留在同一页面中。是我做错了什么还是有我不知道的异常?

【问题讨论】:

  • 如何称呼“编辑”?
  • EditProductAdmin 控制器的一部分,对吗?
  • 正如@Liam 所问,我们可以看到从哪里调用了该操作吗?是从剃刀的角度来看的吗?
  • 从 js 文件调用动作。 $http.post("/Product/EditProduct", productId);是的,EditProduct 是管理控制器的一部分。

标签: c# asp.net-mvc


【解决方案1】:

正如 Suman Pathak 在 cmets 中所说,MVC 不使用 ajax 调用进行重定向。所以我通过js文件传递了标识符:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多