Wednesday, November 09, 2011

MVC3 :: Multiple Submit button

You may need a form with more than one submit button.
Here you have the buttons at the Razor markup


 <input type="submit" value="Back" name="actionType" class="btn medium secondary" />
 <input type="submit" value="Save draft" name="actionType" class="btn medium secondary" />
 <input type="submit" value="Publish" name="actionType" class="btn medium primary" />



You have one action to submit the form to which name is "Edit" for example.
The solution is as you noticed above I've added name="actionType" for all submit buttons.
Now in the Edit action you have to add one extra parameter for actionType as below:

 public ActionResult Edit(string actionType)
{
    switch(actionType)
     {
               // add ur cases here
      }
}


Welcome

Welcome to my technical blog.
Here i hope to be able to share my technical experience overall the world.
You are welcomed to visit, read, share and contribute with your ideas and comments.
Good luck