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());
开发者_如何学C check.write("can I save immediately? :- ", TryUpdateModel(timesheet).ToString());
TryValidateModel - returns true TryUpdateModel - returns false
Any recommendations?
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.
精彩评论