パラメータを渡すこのメソッドがあり、すべてのパラメータが値を保持しますが、それらをviewModelに割り当てると、それらの1つがnullになり、理由がわかりません:
[HttpPost]
[ValidateInput(false)]
public ActionResult Create(VisitViewModel viewModel, Guid[] associatedCasesSelected, Guid[] selectedParties)
{
if (!ModelState.IsValid)
{
viewModel.Time = _timeEntryHelper.Value;
AddLookupsToViewModel(viewModel);
return View(viewModel);
}
var visitEntry = Mapper.Map<VisitViewModel, VisitEntry>(viewModel);
visitEntry.VisitDate = _timeEntryHelper.AddTimeToDate(visitEntry.VisitDate);
visitEntry.UserId = _currentUser.UserId;
visitEntry.OfficeId = _currentUser.OfficeId;
viewModel.AssociatedCasesSelected = associatedCasesSelected;
viewModel.PartiesSelected = selectedParties;
try
{
_visitEntryService.Create(visitEntry, associatedCasesSelected, selectedParties);
this.FlashInfo(string.Format(Message.ConfirmationMessageCreate, Resources.Entities.Visit.EntityName));
}
catch (RulesException ex)
{
ex.CopyTo(ModelState);
}
if (ModelState.IsValid)
return RedirectToAction("Edit", "Case", new { caseId = viewModel.CaseId });
AddLookupsToViewModel(viewModel);
return View(viewModel);
}
これは行です:
viewModel.PartiesSelected = selectedParties;
selectedParties は 1 つの値を保持する必要がありますが、それをpartySelected に割り当てると、デバッグ中にその PartiesSelected = null; が表示されます。
これは私のviewModelでpartiesSelectedです:
public IList<Guid> PartiesSelected { get; set; }