How to completely decouple view and model in MVC

后端 未结 4 558
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 14:20

In my first example I have a Model like so:

public class GuestResponse
{
    [Required(ErrorMessage = \"Please enter your name\")]
    public string Name { g         


        
4条回答
  •  一整个雨季
    2020-12-11 14:32

    What you have noticed is one of the weaknesses of the MVC model. And it's why some people are moving away from it. Instead we have a lot of other patterns that better decouple them.

    In MVVM you have a view and a model, but in between you have the modelview which should hold all the presentation logic. This completely decouples the view and the model.

    You can also do this with an interface, but that's another form of decoupling. Even if you decouple the classes you still have dependencies between the layers (the view layer and the model layer will have some link).

提交回复
热议问题