[英]How do you pass data from one view to another using the same controller but different actions? ASP.Net & Microsoft Graph
[英]How do I pass variables along the actions within the same controller?
就是這種情況。
當我從ActionA轉到ActionB然后是ActionC時,到達Actionc時是否可以檢索ActionA的URL參數,在這種情況下為“ 1”? 反之亦然?
任何幫助,將不勝感激! :)
您需要在創建的URL中提供所有先前的參數,以執行其他操作。 由於網絡是無狀態的,因此每個請求都必須包含完成該請求所需的所有信息。
@Html.ActionLink("Action B", "ActionB",
new{id=listItem.actionBId, actionAId = Model.Id});
接着:
public ActionResult ActionB(int id, int actionAId)
{
...
}
避免這種情況的唯一方法是,如果ActionB所處理的項目某種程度上與ActionA的項目相關,則在這種情況下,您希望從服務器端推斷該信息:
public ActionResult ActionB(int id)
{
int actionAId = GetActionAItemByB(id).Id;
...
}
這取決於您如何從一個動作轉到另一個動作。 一種標准方法是RedirectToAction()
方法,該方法具有重載以包含路由值 :
return RedirectToAction("ActionB", new { id = x, someOtherRouteValue = y });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.