tags:

views:

56

answers:

2

Hi,

I'm knocking together a wizard like web app that will take input in a form and conditionally redirect to a confirmation page if the item entered already exists. Something along the lines of

"there is already a product in the system with that name are you sure you wish to continue?".

I can have an action "Confirm" on my controller for this but this action should only ever be called by the initial "Add" action.

My question is, what's the best way to control controller action call order. Obviously someone could enter the //Confirm url and spoof the data.

Hope I'm making sense.

Thanks,

+1  A: 

You can't control controller action call order.

You can, however, promote this concept to something you code into your application.

I can think of a few ways to ensure that a visitor saw one step before the other: session state, cookies, passing a token from action to action, and tempdata in asp.net mvc.

TempData is going to be easiest, I bet, if you just want to bang this feature out.

Have Add put a special value in TempData before it redirects to Confirm. If Confirm doesn't see that value in TempData it redirects back to Add. If it's there, Confirm does its normal business.

Matt Hinze
+2  A: 

You want the user to confirm something sometimes, right?

If so, submit the form to the confirm action; then

public ActionResult Confirm(MyObject mObj, string confirmButton )
{

   if( NotAlreadyExists(mObj) || confirmButton )
      return RedirectToAction("Create", mObj)
  else
  {
      ModelState.AddModelError("DuplicateProduct","Please confirm");
      ViewData["showConfirm"] = true;
      return View(mObj);
 }
}

Ofourse, then you hardly need a special action, as you could simply place your datacontext create code instead of the RedirectToAction, but whatever...

The view will then need to look for showConfirm, and show the message + confirmation button.

Soraz