После того, как я хочу обновить пользовательские записи и когда я нажимаю кнопку Обновить, я получаю
An unhandled exception occurred while processing the request.
ArgumentNullException: Value cannot be null.
Parameter name: source
System.Linq.Enumerable.Select<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, TResult> selector)
Вот моя функция для обновления пользовательской записи:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(int id, AppointmentDetailsViewModel objAppointmentVM)
{
if(ModelState.IsValid)
{
objAppointmentVM.Appointment.AppointmentDate = objAppointmentVM.Appointment.AppointmentDate
.AddHours(objAppointmentVM.Appointment.AppointmentTime.Hour)
.AddMinutes(objAppointmentVM.Appointment.AppointmentTime.Minute);
var appointmentFromDb = _db.Appointments.Where(a => a.Id == objAppointmentVM.Appointment.Id).FirstOrDefault();
appointmentFromDb.CustomerName = objAppointmentVM.Appointment.CustomerName;
appointmentFromDb.CustomerEmail = objAppointmentVM.Appointment.CustomerEmail;
appointmentFromDb.CustomerPhoneNumber = objAppointmentVM.Appointment.CustomerPhoneNumber;
appointmentFromDb.AppointmentDate = objAppointmentVM.Appointment.AppointmentDate;
appointmentFromDb.isConfirmed = objAppointmentVM.Appointment.isConfirmed;
if(User.IsInRole(SD.SuperAdminEndUser))
{
appointmentFromDb.SalesPersonId = objAppointmentVM.Appointment.SalesPersonId;
}
_db.SaveChanges();
return RedirectToAction(nameof(Index));
}
return View(objAppointmentVM);
}
Эта функция предназначена дляВыпадающее меню, в котором отображаются пользователи из БД
public static IEnumerable<SelectListItem> ToSelectListItemString<T>(this IEnumerable<T> items, string selectedValue)
{
if(selectedValue == null)
{
selectedValue = "";
}
return from item in items
select new SelectListItem
{
Text = item.GetPropertyValue("Name"),
Value = item.GetPropertyValue("Id"),
Selected = item.GetPropertyValue("Id").Equals(selectedValue.ToString())
};
}
Есть идеи, где я ошибся?