I have two submit buttons on my form, one to save, one to resolve:
<input type="submit" name="submitButton" value="Save" class="btn btn-default" />
<input type="submit" name="submitButton" value="Resolve" class="btn btn-default" />
I am dealing with these in the Controller like so:
//POST: Exceptions
[HttpPost]
public ActionResult Edit(string submitButton, PersonViewModel personViewModel)
{
switch (submitButton)
{
case "Save":
return (Save(person));
case "Resolve":
return (Resolve(person));
default:
return (View());
}
}
I know that I can make certain properties required by using data annotations on my view model, however I only want these particular properties to be required when the user attempts to Resolve, Save should have no such restrictions.
What is the best way of achieving this?
update
The above blog seems to suggest that you can assign an input you wish to be excluded from validating prior to submit by giving it a class and adding some JS like so:
<input id="btnSubmitSave" type="submit" name="submitButton" value="Save" class="btn btn-default ignore" />
<input id="btnSubmitResolve" type="submit" name="submitButton" value="Resolve" class="btn btn-default" />
$(function () {
var settngs = $.data($('form')[0], 'validator').settings;
settngs.ignore = ".ignore";
});
Unfortunately this is still attempting to validate when I click the Save button.