I followed the routine suggested in SO the one with two buttons with the same name.
I have two submit buttons in my View.
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="SaveAndAddMore" name="command" class="btn btn-default" />
<input type="submit" value="SaveAndContinue" name="command" class="btn" />
</div>
</div>
In the controller, I am checking (or atleast want to check) the value of command passed
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreateEducation([Bind(Include = "DegreeEarned,Description,Institution,AcquiredDate,EducationStartDate,EducationEndDate,Department,InstitutionAddress,ReferenceName,ReferencePhoneNumber,ReferenceEmail")] Education ed, Command command)
{
if (ModelState.IsValid)
{
var user = userManager.FindById(User.Identity.GetUserId());
user.ExpertInfo.Educations.Add(ed);
db.SaveChanges();
if (command == Command.SaveAndAddMore)
return RedirectToAction("CreateEducation");
else
return RedirectToAction("CreateWorkExperience");
}
return View(ed);
}
however / when I click on SaveAndAddMore
button (the one with the default class), my controller method is invoked correctly with the correct command value and all is well.
until I click on SaveAndContinue
. On this instance, the controller is not passing any value for command.
The parameters dictionary contains a null entry for parameter 'command' of non-nullable type 'xxx.Models.Command' for method 'System.Web.Mvc.ActionResult CreateEducation(Experts.Models.Education, Experts.Models.Command)' in 'xxx.Areas.Expert.Controllers.ExpertInfoesController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
The Command type is an enum
public enum Command { SaveAndAddMore, SaveAndNext, Save, Delete }
where have I gone wrong?