RIA 服务验证
我训练在客户端上验证我的实体,但它不起作用。我有“必需”以及范围和字符串长度属性。问题是只需要在客户端进行验证。我之前在客户端有 à validate 方法 我调用 SubmitChanges。但仅验证必需的属性。然后调用 SubmitChanges 并引发异常,因为我仍然存在范围或字符串长度验证错误。我正在使用 TryValidateObject:可以吗?
请帮忙:-)
I'm train to do the validation of my entity on the client, but it does not work. I've "required" and range and stringlength attributes. The problem is that only required is validating on the client side. I have à validate method on the client before
I call SubmitChanges. But only required attribute is validated against. Then SubmitChanges is called and raises an exception, because I still have range or stringlength validation errors. I'm using TryValidateObject: is it ok?
Please help :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您调用 SubmitChanges 时,它会返回一个 SubmitOperation,它具有一个名为 HasError 的属性。如果这是真的,则意味着一个或多个实体出现错误。您还可以使用 EntitiesInError 属性,它将带您返回所有有错误的实体,包括validationErrors。
与 TryValidate 相比,这使您可以更好地控制错误。如果有错误,您还可以取消 SubmitOperation...
When you call SubmitChanges it returns a SubmitOperation which has a property called HasError. If this is true then it means one or more of the entities are in Error. You can also use the EntitiesInError Property that will bring you back all the Entities with any errors including validationErrors
This gives you more control over the errors than doing the TryValidate. You can also then cancel the SubmitOperation if it has errors...
无法进行验证,因为 TryValidateObject 仅执行“必需”验证。我们必须将最后一个参数设置为 true 来验证所有验证类型(Range Stringlength ...)。当然,在 SubmitChanges 方法中进行验证也不错,如果它已经可以在客户端进行验证,那么它就不会在服务器上进行验证。
The validation could not occur, because TryValidateObject only performs "Required" validation. We have to set the last parameter to true to validate all validation types (Range Stringlength ...). For sure validating in the SubmitChanges method is also not bad and it not go on the server for the validation if it can validate on the client-side already.