Created
July 6, 2011 01:34
-
-
Save waldyrfelix/1066349 to your computer and use it in GitHub Desktop.
Exemplo de ViewModel com SelectList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AgendamentoDePagamentoViewModel | |
{ | |
public AgendamentoDePagamentoViewModel() {} // construtor vazio necessario para para o modelbinder | |
public AgendamentoDePagamentoViewModel(IEnumerable<Conta> contas) | |
{ | |
Contas = MontarSelectListDeContas(contas); | |
} | |
public SelectList Contas { get; set; } | |
[Required(ErrorMessage = "Selecione uma conta a pagar")] | |
[DisplayName("Conta a pagar")] | |
public int? IdDaContaSelecionada { get; set; } | |
[Required(ErrorMessage = "Digite uma data")] | |
[DisplayName("Data do agendamento")] | |
public DateTime? DataDoPagamento { get; set; } | |
public SelectList MontarSelectListDeContas(IEnumerable<Conta> contas) | |
{ | |
List<SelectListItem> itensDaLista = contas | |
.Select(c => new SelectListItem {Value = c.Id, Text = c.Descrição}) | |
.ToList(); | |
itensDaLista.Insert(0, new SelectListItem {Text = "SELECIONE UMA CONTA"}); | |
return new SelectList(itensDaLista, "Value", "Text"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment