淘汰赛 + mvc 3 + 验证 [英] Knockout + mvc 3 + Validation

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

问题描述

在控制器中,我希望能够访问模型的客户端验证规则.我已经使用数据注释附加了一些属性,并希望能够通过 ajax 调用将某些内容传回客户端,以便我可以自动构建 jquery 验证选项.

In the controller I would like to be able to get to the client validation rules of the model. I've attached some attributes using data annotations and would like to be able to pass something back to the client via the ajax call so I can then build the jquery validate options automatically.

通常这是使用不显眼的东西免费完成的,但我正在尝试利用淘汰赛绑定,同时仍然不必在服务器和客户端上复制验证规则.

Normally this is done for free with the unobtrusive stuff, but I'm trying to leverage knockout binding, while still not having to replicate the validation rules on both the server and client.

如果不在模型服务器端使用反射,我有点不确定如何实现这一点.

Without using reflection on the model server side I'm a little unsure on how to achieve this.

推荐答案

在我的 Mvc Controls Toolkit 中我开发基于淘汰赛库的助手.这些帮助程序不仅有助于编写淘汰赛代码,还通过非侵入式验证和全球化来增强淘汰赛库.此外,绑定机制得到了增强,以包含复杂的控件,例如 DatetimePicker 和其他复杂"(由不同的 html 部分构成)控件.

In my Mvc Controls Toolkit I developed Helpers based on the knockout library. These helpers not only help in writing the knockout code, but enhance the knockout library with Unobtrusive validation and globalization. Moreover, the binding mechanism is enhanced to include complex controls such as a DatetimePicker, and other "complex" (made by different html parts) controls.

最后,可以通过 Razor 助手定义敲除模板.

Finally, knockout templates can be defined through Razor helpers.

此处查看文档,这里此处此处.我还有一些教程展示了如何使用我的助手实现高级功能:

See the documentation here, here, here and here. I also have some tutorials that show how to implement advanced features with my helpers:

使用 Mvc 控件工具包的客户端模板进行低带宽传输

使用客户端模板处理大量数据

使用客户端模板处理大量数据 2

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

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