[英]SetActualResponseType with same method in the same controller with different routes
[英]A controller method that calls a different method on the same controller
我有一個控制器方法:
public ActionResult Details(int id)
{
Order order = OrderFacade.Instance.Load(id);
return View(order);
}
用於95%的可能調用。 對於其他5%,我需要在傳遞到立面之前操縱id
的值。 我想在同一控制器內創建一個單獨的方法,該方法執行該操作,然后調用此(詳細信息)方法。
該方法的簽名是什么樣的? 調用主Details方法的語法是什么?
public ??? ManipulatorMethod(int id)
{
[stuff that manipulates id]
[syntax to call Details(manipulatedID)]
}
mny thx
public ActionResult ManipulatorMethod(int id)
{
//[stuff that manipulates id]
int _id = id++;
//[syntax to call Details(manipulatedID)]
return RedirectToAction("Details", new { id = _id });
}
//假設{id}在路由上(通常在默認路由中)
如果您將直接調用manipulator方法作為對控制器的操作,則可以執行以下操作:
public ActionResult ManipulatorMethod( int id )
{
// Do something to id
return Details( id );
}
如果所有訪問都將通過“詳細信息”操作進行,則可以執行以下操作:
public ActionResult Details( int id )
{
if( IdNeedsManipulation( id ) )
id = ManipulateId( id );
return View( id );
}
private int ManipulateId( int id )
{
// Do something to id
return id;
}
private bool IdNeedsManipulation( int id ) { return ...; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.