ViewModel vs. Model of data validation in MVVM

Source: Internet
Author: User

MMVM mode.

View is bound to ViewModel and then executes some commands to request an action from it. In turn, ViewModel communicates with model, ViewModel tells the model update to respond to the UI.

This makes building UI designs for apps relatively independent and easy to replace with UI design ("Do whatever you want" to design your interface). At the same time, as the UI and functionality become more and more loosely coupled, the testability of functionality becomes stronger.

Verify in two places:

1. In the ViewModel

2. In model

Is it redundant?

The checksum in ViewModel is primarily used to verify the integrity, correctness and accuracy of input data when interacting with users.

Validation in model focuses on the validation of constraints in the database.

So the verification of these two positions from the focus and its role should be said fragmentation, but more or less redundant suspicion.

If the model is in the EntityFramework entity, the constraints on the entity are ultimately in the database (Eg.sqlserver). Not in C # code.

Unless you System.ComponentModel.DataAnnotations.IValidatableObject yourself in the entity.

Is it more reasonable to verify in that position?

Many times we are unable to say the absolute, unless we are discussed in a certain condition.

It's the same here. We cannot arbitrarily say that it is appropriate to verify in that place, it depends entirely on our application scenario and the software architecture design.

Reference

[WPF Series]-data Validation

Overview of the "WPF series" Basic Learning-WPF Design Patterns

Illustrations of MVC,MVP and MVVM

ViewModel vs. Model of data validation in MVVM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.