knockout.js - Breeze 和 Knockout 中的验证

标签 knockout.js asp.net-mvc-4 breeze

I've recently added Breeze to a project using Knockout and ASP.NET MVC4. I really like Breeze and it saves a lot of coding.

I have used Knockout validation and like how it validates a property field text box on data entry and the way the error message is displayed.

I would like to use a combination where the validation requirements are defined in the back-end with C# attributes on the object properties, the validation requirements are received in the metadata and then Knockout validation can be used.

I think I can work around it by defining the properties in the front end and applying Knockout validation eg

classProperty.extend({ required: true })
             .extend({ minLength: 3 });

Is there a way to use Knockout validation without having to apply the validation requirements in the front-end? If not, are you considering doing this?



这个问题是由 johnvarney 在我们的 IdeaBlade 论坛上发布的。我在这里重新发布问题和答案,因为我认为它对 Breeze Stack Overflow 社区有用。

最佳答案

您可能已经注意到,Breeze 已经基于元数据执行验证。基本的“验证”规则,例如是否需要一个属性、它的数据类型以及它的长度(如果字符串在服务器上自动生成并发送到客户端)。这些验证规则也可以通过直接修改客户端上的“验证”元数据来扩展。

API 文档中提供了有关此主题的更多信息:http://www.breezejs.com/sites/all/apidocs/classes/Validator.html以及在 Breeze Samples 下载中的“DocCode”示例目录中。

我们还计划提供有关如何将 Breeze 验证“连接”到各种第三方库(例如 jQuery 和 Knockout)的示例。不幸的是,这些示例目前不是高优先级,因为需要处理其他高度要求的功能。您可能希望通过我们的 Breeze User Voice https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions 为这些示例的工作投票。 .在决定下一步做什么时,我们会认真对待该地点。

关于knockout.js - Breeze 和 Knockout 中的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13616621/

相关文章:

c# - 使用 DotnetopenAuth 时报告和记录错误

breeze - BreezeJS 是否应该使用 Durandal 在单页应用程序中跨页面共享实体管理器?

javascript - 当 Breeze 导航属性受权限控制时访问它们

c# - ASP.NET MVC 4 FilePathResult 和静态文件处理程序

javascript - 进行数据绑定(bind) :click work like a marker. addListener()

javascript - Knockout js 从其他 View 模型收集数据

javascript - 如何使用 knockout.js 单击时将数据从一个元素填充到另一个元素

asp.net-mvc-4 - "You do not have permission to view this directory or page."在带有 ASP.NET MVC4 的 IIS7.5 上

knockout.js - ko.validation.group 没有在我的嵌套 observableArray 上检测到我的错误

javascript - self=嵌套 View 模型中的这种奇怪行为