繁体   English   中英

如何从ASP.NET MVC中的其他操作返回视图

[英]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 });
}

请注意, idIdInstanceDetailsLane操作方法中的参数名称匹配。

暂无
暂无

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

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