模型对象验证 (TryValidateModel) 但不更新 (TryUpdateModel)
模型对象拒绝在生产服务器上更新,但在开发计算机上没有问题。出于测试目的,我检索模型对象,然后立即检查其验证和更新状态,例如:
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 - 返回 true TryUpdateModel - 返回 false
有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
验证和绑定是不同的。通常可以绑定无效数据(这是一项功能;它使得在出现错误时重新显示页面变得更加容易)和“有效”数据(根据您的验证规则,如果有的话)有时由于打字冲突而无法绑定。
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.