In the best scenarios, try to avoid them as much as possible. They start off quite simply, but later all of this can turn into a lot of spaghetti codes. Saying that this is not always possible and largely inevitable that you will have to do them.
Usually you separate your views or (have several partial views) and then select the if / else bit on the controller. This ensures that your ViewModels will also be different.
-
As a rule, from my experience I always try to understand the business perspective of the views, not the technical ones. Sometimes your two views may look very similar right now, and it may only take an if / else pair to distinguish each other, but they are different in different ways, and itโs obvious that each view will have many new requirements in each line that fully reflect its different from the other. Given the business perspective, you should create separate views and viewing models for both.
source share