验证:型号或视图模型 [英] Validation: Model or ViewModel

查看:104
本文介绍了验证:型号或视图模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该在哪里使用验证时的ViewModels使用MVC(MVVM),对模型或视图模型驻留? (或两者或两者都不是)?为什么?我在ASP.NET MVC的V2即将发光提起这事特别。

Where should validation reside when using ViewModels with MVC (MVVM), on the Model or the ViewModel? (Or both or neither)? And why? I bring this up especially in light of V2 of ASP.NET MVC coming out soon.

对复杂/自定义的验证什么?

What about complex/custom validation?

推荐答案

任何企业特定的验证应该是在模型中。任何网站特定的验证可以在这两个模型和/或视图模型来完成。这样,你的业务逻辑(型号)可背后不同的界面(在Windows,Web窗体等),您的验证移动将保持不变。

Any business specific validation should be in the Model. Any web site specific validation could be done in both the Model and/or ViewModel. This way your business logic (Models) can move behind a different interface (Windows, Web Forms, etc.) and your validation will stay intact.

这篇关于验证:型号或视图模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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