添加数据注解编程 [英] add data annotations programmatically

查看:92
本文介绍了添加数据注解编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作就是使用ASP应用MVC3 .NET 4

I am working on an asp mvc3 app that is using .NET 4.

不过,我想使用的模型是一个使用类库的 .NET 3.5 并不能更改。

However the model I want to use is in a class library that is using .NET 3.5 and cannot change.

我可以添加在 .NET 4 数据批注的在我的控制器模型的一些性质编程方式来获得一些简单的验证?

Can I add the .NET 4 data annotations to some properties in my model in the controller programatically to get some easy validation?

推荐答案

创建自己的ModelMetadataProvider,这应该千方百计想让你想要

Create your own ModelMetadataProvider and this should do want you want

http://www.dotnetcurry.com/ShowArticle.aspx?ID=715

这篇关于添加数据注解编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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