[英]How to return a view from a different action in ASP.NET MVC
我有一个名为DetailsLane
的视图和另一个AddItem
。 呈现DetailsLane
,它将返回带有属性的模型类。 AddItem
操作位于同一控制器内,但是当我完成此操作内必须执行的操作后,就无法重新渲染DetailsLane
来更新视图。
该视图被称为第一次:它起作用了!
public ActionResult DetailsLane(int? id, int? IdInstance)
{
return View(get(IdInstance, id));
}
public ActionResult AddLine(FormCollection collection)
{
// I did my stuff in here, and I want to return the initial View or,
// validate something from the collection.
return DetailsLane(val, val); // doesn't work!
}
您想使用RedirectToAction
并且可以传递参数,如下所示
public ActionResult AddLine(FormCollection collection)
{
// I did my stuff in here, and I want to return the initial View or,
// validate something from the collection.
return RedirectToAction("DetailsLane", new { id = val1, IdInstance = val2 });
}
请注意, id
和IdInstance
与DetailsLane
操作方法中的参数名称匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.