验证在微风和淘汰赛 [英] Validation in Breeze and Knockout

查看:153
本文介绍了验证在微风和淘汰赛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近添加了微风使用淘汰赛和ASP.NET MVC4的项目。我真的很喜欢微风,这样可以节省大量的编码。

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.

我想使用的对象属性所在的验证要求在后端使用C#定义的属性组合,验证要求在元数据接收,然后淘汰赛验证即可使用。

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论坛。我重新张贴的问题,因为我认为这将是微风堆栈溢出社会有用的答案在这里。

This question was posted by johnvarney on our IdeaBlade forums. I am reposting the question and answer here since I think it will be useful to the Breeze Stack Overflow community.

推荐答案

正如你可能已经注意到,微风基于元数据已经进行验证。基本的验证的规则,如是否需要一个属性,它的数据类型,它的长度,如果一个字符串会自动在服务器上生成,然后发送到客户端。这些验证规则,也可以通过直接修改客户端上的验证元数据扩展。

As you've probably noticed, Breeze already performs validations based on metadata. Basic "validation" rules such as whether a property is required, it's datatype and it's length if a string are automatically generated on the server and sent down to the client. These validation rules can also be extended by directly modifying the "validation" metadata on the client.

有关此主题的更多信息的API文档中可用两种:<一href=\"http://www.breezejs.com/sites/all/apidocs/classes/Validator.html\">http://www.breezejs.com/sites/all/apidocs/classes/Validator.html以及在微风样本下载文件code的样本目录中。

More information on this topic is available both within the API documentation: http://www.breezejs.com/sites/all/apidocs/classes/Validator.html as well as within the "DocCode" sample directory in the Breeze Samples download.

我们还计划于提供如何连接清风验证,以各种第三方库,如jQuery和淘汰赛的例子。不幸的是,这些例子目前还不是一个高优先级,因为其他高要求的功能工作。你可能想投票工作在这些例子中我们微风用户音色<一个href=\"https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions\">https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions.我们采取认真地点约下一步该怎么做决策。

We are also planning on providing examples of how to "connect" breeze validation to various third party libraries, such as jQuery and Knockout. Unfortunately, these examples are not currently a high priority because of work on other highly requested features. You might want to vote for work on these examples on our Breeze User Voice https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions. We take that venue seriously in making decisions about what to do next.

这篇关于验证在微风和淘汰赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆