Posting a form and redirecting to action ASP.NET MVC
asp.net-mvc
Solution
You can have multiple submit buttons on your form:
<input type="submit" name="step1" value="Step 1"/>
<input type="submit" name="step2" value="Step 2"/>
<input type="submit" name="step3" value="Step 3"/>
and in your action:
public ActionResult Action(FormCollection form)
{
if (!string.IsNullOrEmpty(form["step1"]))
{
// Step 1 button was clicked
}
else if (!string.IsNullOrEmpty(form["step2"]))
{
// Step 2 button was clicked
}
else if (!string.IsNullOrEmpty(form["step3"]))
{
// Step 3 button was clicked
}
...
}
Problem
I have a navigation bar that uses JQuery to move between 4 stages of signup process. However I need to make sure everything is working with JS disabled. So I have these 4 link images at the bottom of the page and I need so that if one is clicked it posts to the current action so I can save all the form data and then redirect to the next stage. The redirect is easy enough as I will just pass a parameter in the route or form but I don't know how to post the method using just action links. I could put 4 different submit buttons with different classes for the image backgrounds etc but this feels wrong. Any ideas?