views:

47

answers:

2

I have a controller method:

  public ActionResult Details(int id)
  {
      Order order = OrderFacade.Instance.Load(id);
      return View(order);
  }

that is used for 95% of possible invocations. For the other 5% i need to manipulate the value of id before passing to the facade. I'd like to create a separate method within this same controller that executes that manipulation and then calls this (Details) method.

What would the signature of that method look like? What is the syntax to call the main Details method?

public ??? ManipulatorMethod(int id)
{
    [stuff that manipulates id]

    [syntax to call Details(manipulatedID)]
}

mny thx

+1  A: 
public ActionResult ManipulatorMethod(int id) 
{ 
    //[stuff that manipulates id] 
    int _id = id++;

    //[syntax to call Details(manipulatedID)] 
    return RedirectToAction("Details", new { id = _id });
} 

//assuming that {id} exists on the route (usually in the default route)

CRice
A: 

If you will invoke the manipulator method directly as an action on the controller you can do this:

public ActionResult ManipulatorMethod( int id )
{
    // Do something to id
    return Details( id );
}

If all access will be through the Details action then you can do this:

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 ...; }
Paul Alexander