Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
MVVM - How to handle anonymous types composed of models inside ViewModel

Currently my view has the need to receive a List containing information from two different models.

Something like this

public class ViewModel
{
    [JsonProperty("")]
    public List<Unknown> viewModelList;
}

This Unknown type would have information from two different models, like so.

public class FirstModel
{
    int w;
    int x;
}

public class SecondModel
{
    int y;
    int z;
}

public class Unknown //Model or ViewModel?
{
    [JsonProperty("")]
    int w; //From FirstModel

    [JsonProperty("")]
    int x; //From SecondModel
}

My question is, this Unknown type would have to be a Model? My idea of a Model is that they represent Business entities or Database entities, and ViewModel are abstractions of those models. In this case, Unknown is nothing, but an abstraction of both FirstModel and SecondModel, so I think it characterizes more as a ViewModel, than a Model, but then if I treat it as a ViewModel, I'm unable to make a List out of it, because otherwise my code would be as follows

public class ViewModel
{
    [JsonProperty("")]
    public List<UnknownViewModel> viewModelList;
}

It would be a ViewModel inside a ViewModel, and I don't know if this is common or good practice.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

There's absolutely no functional difference in what you call it. What matters is how you use the types.

A model is simply a type that contains data (or state). And a view-model, as its name suggests, is the model used as the backing for a view (or presentation). That's all.

Here, in your example, you're using Unknown as a model -- one that's being used as the element type of a collection property of a type that will presumably be used as a view-model.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda