ASP.NET MVC 2验证:它应该在哪里去了?在模型或视图模型类的? [英] ASP.NET MVC 2 Validation: Where should it go? in the model or viewmodel classes?

查看:71
本文介绍了ASP.NET MVC 2验证:它应该在哪里去了?在模型或视图模型类的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用automapper我的模型映射到视图模型类来传递给我的看法。

I am using automapper to map my models to viewmodel classes to pass to my view.

我的问题还真是验证应该去哪里?我打算使用元数据装饰品 - MVC 2的一个特征

My question really is where should the validation go? I was planning on using the MetaData decorations - a feature of mvc 2.

但是,无论是在模型或视图模型?

But either in the model or viewmodel?

或者在这两个地方?

任何想法真的AP preciated

Any ideas really appreciated

推荐答案

验证应在视图模型做最小,因为这是你得到什么的操作参数,包含用户输入。你也可以有验证的模式。

Validation should be done minimum at the View Model because this is what you receive as action argument and contains the user input. You could also have validation at the model.

这篇关于ASP.NET MVC 2验证:它应该在哪里去了?在模型或视图模型类的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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