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

查看:91
本文介绍了淘汰赛+ 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控制工具包我开发了基于助手在淘汰赛库。这些帮助不仅在书面淘汰赛code帮忙,但加强与不引人注目的验证和全球化淘汰赛库。此外,该约束机制的增强,包括复杂的控制,例如一个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.

最后,淘汰赛模板可以通过剃刀助手定义。

Finally, knockout templates can be defined through Razor helpers.

看到这里的文档 ,<一个href=\"http://mvccontrolstoolkit.$c$cplex.com/wikipage?title=Client%20Block%20complete%20example\">here, 这里和的此处。我也有一些教程,说明如何实现我的助手高级功能:

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

<一个href=\"http://www.dotnet-programming.com/post/2011/10/28/Low-BandWidth-Transfers-with-Client-Side-Templates-of-the-Mvc-Controls-Toolkit.aspx\">Low频宽传输和MVC控件工具包的客户端模板

<一个href=\"http://www.dotnet-programming.com/post/2011/10/29/Handling-Big-Amounts-of-Data-with-Client-Side-Templates.aspx\">Handling大数据与金额客户端模板

<一个href=\"http://www.dotnet-programming.com/post/2011/10/29/Handling-Big-Amounts-of-Data-with-Client-Side-Templates-2.aspx\">Handling大数据与金额客户端模板2

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

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