title: Submit vs Submit & Close buttons
body: <p>On my "Create" view for my model, I'd like a "Submit" button as well as a "Submit &amp; Close" button. I was looking at the answer to <a href="https://stackoverflow.com/questions/853738/how-do-you-close-an-asp-net-mvc-page-from-the-controller/853752">this question</a> for information on how to close a page from a controller action (although I see some comments saying that this isn't possible--is there a workaround for that?).</p>
  
  <p>These are the buttons currently:</p>
  
  <pre><code>@using (Html.BeginForm()) 
  {
      @Html.HiddenFor(model =&gt; model.Project.ProjectID);
  
      @Html.AntiForgeryToken()
  
      @Html.ValidationSummary(true, "", new { @class = "text-danger" })
      &lt;div class="save-buttons"&gt;
          @if (Model.ReadOnly)
          {
              &lt;button type="button" id="close_page" onclick="closeWindow();"&gt;Close&lt;/button&gt;
          }
          else
          {
              &lt;button type="submit"&gt;Save Project&lt;/button&gt;
              if (Model.Project == null)
              {
                  &lt;button type="button"&gt;Delete Project&lt;/button&gt;
              }
              else
              {
                  &lt;button type="button" onclick="deleteProject(@Model.Project.ProjectID, @Model.Project.SubmissionNumber);"&gt;Delete Project&lt;/button&gt;
              }
              &lt;button type="button"&gt;Save &amp; Close&lt;/button&gt;
          }
      &lt;/div&gt;
  ... the form itself is below here
  </code></pre>
  
  <p>and the submit action is:</p>
  
  <pre><code>public ActionResult Create([Bind(Include = "ProjectName,ProjectDescription,DateReceived,EffectiveDate,ExpirationDate,GeneralContractor,ProjectTerm,ProjectType,SubmissionNumber,PolicyNumber,Status,Underwriter,Division,BrokerCity,TAName,Branch,FirstNamedInsuredAddress,FirstNamedInsured,ProjectAddress")] Project project)
  {
      if (ModelState.IsValid)
      {
          if (project.ProjectID &lt;= 0)
          {
              db.Projects.Add(project);
          }
          else
          {
              db.Entry(project).State = EntityState.Modified;
          }
          db.SaveChanges();
          return RedirectToAction("Create", new { sub_num = project.SubmissionNumber });
      }
  
      var model = new ProjectViewModel()
      {
          Project = db.Projects.Find(project.ProjectID),
          States = GetSelectListItems(GetAllStates()),
          Branches = GetSelectListItems(GetAllBranches()),
          Divisions = GetSelectListItems(GetAllDivisions()),
          ProjectTypes = GetSelectListItems(GetAllProjectTypes()),
          Statuses = GetSelectListItems(GetAllStatuses()),
          ReadOnly = false,
          Cleared = false,
          EditMode = false
  };
      return View("Maintenance", model);
  }
  </code></pre>
  
  <p>My problem comes with differentiating which button sent the browser to the submit method. I've come up with a few different possibilities but I'm not sure if any of them are possible (I don't think they are):</p>
  
  <p>First is to create a boolean model property that is true when the page should close after submitting and false otherwise. Then I can wrap my RedirectToAction in an if statement like so:</p>
  
  <pre><code>if (Model.Done) {
      return JavaScript("window.close();");
  }
  else
  {
      return RedirectToAction("Create", new { sub_num = project.SubmissionNumber });
  }
  </code></pre>
  
  <p>But I don't know how I could set this property on button click. I don't think this is possible so I can't do this but correct me if I'm wrong.</p>
  
  <p>The other possibility would be to pass an argument to the action when the button is clicked, but I don't know how to do this when it is a <code>&lt;button type="submit"&gt;&lt;/button&gt;</code>.</p>
  
  <p>Does anyone have any suggestions? Thanks!</p>