MVC how to implement two different post actions
- by AnonyMouse
I'm developing this really important squirrel application.
There is a wizard where squirrels are added to the database.
So say there are three screens to this wizard:
Squirrel name details
Height and weight
Nut storage
So at each step of the wizard I'm wanting to save the details to the database.
The Height and weight view looks like:
@model HeightWeightViewModel
@{
ViewBag.Title = "Height and weight";
}
<h2>Height and weight</h2>
@using (Html.BeginForm()) {
<h3>Height</h3>
<div>
@Html.EditorFor(model => model.Squirrel.Height)
</div>
<h3>Weight</h3>
<div>
@Html.EditorFor(model => model.Squirrel.Weight)
</div>
<input type="submit" value="Previous" />
<input type="submit" value="Next" />
}
So I'm hoping that Previous and Next buttons will save these details. The Previous button while saving will also take the user
to the Squirrel name details page. The Next will save and take the user to the nut storage page.
I got the Next button working using:
public ActionResult Edit(SquirrelViewModel squirrelViewModel)
{
_unitOfWork.SaveHeightWeight(squirrelViewModel);
return RedirectToAction("Edit", "NutStorage", new { id = squirrelViewModel.Squirrel.Id });
}
So the Next button saves the details and sends the user to the NutStorage page.
The Previous button does the same as Next but I actually want it to send the user to the first step of the Wizard after saving.
I'm not sure how to do this. Would I have another method to post to for Previous?
I can't image how to implement this.
Maybe I should be using ActionLinks instead of submit buttons but that would not post the details to be saved.
Can anyone suggest how to get the previous button to save and send the user to the first page of the wizard while still
having the Next functionality working?