Klaptrap
Klaptrap

Reputation: 311

Model object validates (TryValidateModel) but does not update (TryUpdateModel)

The Model object refuses to update on production server but has no issues on development machine. For the purposes of testing, I retrieve the model object and then immediately check its validation and update states, for example:

        Timesheet timesheet = _timesheetRepository.GetTimesheet(timesheetId);
        Helpers.ErrorHandler check = new Helpers.ErrorHandler();
        check.write("can I validate immediately? :- ", TryValidateModel(timesheet).ToString());
        check.write("can I save immediately? :- ", TryUpdateModel(timesheet).ToString());

TryValidateModel - returns true TryUpdateModel - returns false

Any recommendations?

Upvotes: 0

Views: 1909

Answers (1)

Craig Stuntz
Craig Stuntz

Reputation: 126547

Validation and binding are different. Invalid data can often be bound (this is a feature; it makes re-displaying a page in the case of an error much easier), and "valid" (per your validation rules, if any) data sometimes can't be bound, due to typing conflicts.

Upvotes: 1

Related Questions