[英]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.