I am trying to ensure that my fields and page options are valid and on one page i want to check and see if an item is selected or not – which a selection is required to save.
I have the following:
in ViewEntry: public IList<Guid> Parties { get; set; }
in my ViewModel: public IEnumerable<Guid> PartiesSelected { get; set; }
Here is my ensure valid code:
public void EnsureValid(VisitEntry visitEntry)
{
var errors = new RulesException<VisitActivityEntryDTO>();
if(visitEntry.Parties == null )
errors.ErrorForModel(string.Format("No {0} selected", Kids.Resources.Entities.Party.EntityNamePlural));
if (errors.Errors.Any())
throw errors;
}
and in my controller my Get Edit method when loading the page I have:
viewModel.PartiesSelected = visitEntry.VisitEntryParties.Select(v=>v.PartyId);
Is it possible in any way that i could possibly have:
viewEntry.Parties = viewModel.PartiesSelected
or
viewEntry.Parties = visitEntry.VisitEntryParties.Select(v=>v.PartyId);
I mainly want to have the selected party to show up in the list of Parties for the ViewEntry so when i validate.
1 Answer