【发布时间】:2013-11-12 13:04:28
【问题描述】:
我想重定向到其他控制器中的操作,但它不起作用 这是我在 ProductManagerController 中的代码:
[HttpPost]
public ActionResult RedirectToImages(int id)
{
return RedirectToAction("Index","ProductImageManeger", new { id=id });
}
这在我的 ProductImageManagerController 中:
[HttpGet]
public ViewResult Index(int id)
{
return View("Index",_db.ProductImages.Where(rs=>rs.ProductId == id).ToList());
}
它很好地重定向到 ProductImageManager/Index 没有参数(没有错误),但是使用上面的代码我得到了这个:
参数字典包含一个空条目 方法的不可为空类型“System.Int32”的参数“ID” 'System.Web.Mvc.ViewResult 索引(Int32)' 在 '...Controllers.ProductImageManagerController'。 可选参数必须是引用类型、可空类型或 声明为可选参数。参数名称:参数
【问题讨论】:
-
RedirectToImages 无法重定向到 ProductImageManager/Index,因为参数顺序无效
-
@jim 我只有一个参数id,那么这里的参数顺序是什么意思?
-
需要
"Index", "ProductImageManager"而不是"ProductImageManager","Index" -
public static void RegisterRoutes(RouteCollection routes)方法体是什么样的?将其添加到消息中 -
@jim 在重定向网址中我得到 /ProductManager/Index 而不是 /ProductManager/Index/1 ,为什么我的参数没有发送?
标签: c# asp.net-mvc redirect asp.net-mvc-5