Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3452062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:12:49+00:00 2026-05-18T09:12:49+00:00

I’m wondering how you might go about implementing multiple form actions when submitting a

  • 0

I’m wondering how you might go about implementing multiple form actions when submitting a form in asp.net mvc 3 RC.

If I’m editing a user, for example I would like to have an action bar with the following buttons;

“Save” | “Save and Close” | “Cancel”

Save – Submits the form and saves, returning you to the edit screen. Could be easily implemented as a standard input/submit button. Nothing special here.

Controller code for this might look like

public ActionResult Edit(UserViewModel model)
{
  ...
  return RedirectToAction("Edit", model.Id");
}

Cancel – Just returns you to previous screen. I was thinking about using an anchor tag for this.

<a href="@Request.UrlReferrer" class="button">Cancel</a>

But I’m stumped on how to implement “Save and Close” when you need to submit the same form data. I was wondering about having a nullable close param maybe?

public ActionResult Edit(UserViewModel model, bool? close)
{
  ...
  return  close.GetValueOrDefault(false) ? RedirectToAction("Index", model.Id" : RedirectToAction("Edit", model.Id");
}

But how do I submit this extra param along with the form in this case?

If possible, I’d like to have a single form action for handling the submit as in the above mockup.

I’m also interested if anyone else has come up with a nice user interaction model around this idea.

Solution

I ended up using Omar’s suggestion below but instead of passing in a string I took in an enum so I don’t have to do string checks in all my controllers.

public ActionResult Edit(UserViewModel model, FormAction actionType)
{
  // pre-check
  if (actionType == FormAction.Cancel)
     // just return user to previous view and don't save.

  // Save code

  if (actionType == FormAction.Save)
     return ...
  else if (actionType == FormAction.SaveAndClose)
     ....
}

Because I wanted a friendlier “Save and Close” text on the <input> button but wanted to use an enum I implemented a custom ModelBinder for FormAction that did the parsing.

I didn’t use a <button> tag because the theming was already in place for <input> tags.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:12:49+00:00Added an answer on May 18, 2026 at 9:12 am

    You can have multiple submit buttons in a form with the same name attribute but different value attributes. Which ever button is clicked, the associated value will be posted to the server.

    You can use a simple link for Cancel but I’ll include it as a button anyway.

    <input type="submit" name="actionType" value="Save" />
    <input type="submit" name="actionType" value="Save and Close" />
    <input type="submit" name="actionType" value="Cancel" />
    

    And in your action, test for the values.

    public ActionResult Edit(string actionType)
    {
        if(actionType == "Save")
        {
            // Save action
        }
        else if (actionType == "Save and Close")
        {
            // Save and quit action
        }
        else
        {
            // Cancel action
        }
    }
    

    If you don’t like having the long text in the value attribute, you can use standard HTML <button> tag which lets you define a separate value and separate text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.