[SOLVED] SelectList always null on POST causes Model State to be Invalid


I understand that the SelectListItems are meant to not return back the items on post and perhaps be null, but because of this my ModelState.IsValid condition is always false and the Studies field which contains the list is the one with the invalid attribute. I tried different methods and am stuck on resolving this


 <label asp-for="Studies" class="form-label"></label>
 <select asp-for="SelectedStudyGuid" asp-items="@Model.Studies" class="form-control" autocomplete="off">
   <option value="">Select Study</option>
 <span asp-validation-for="SelectedStudyGuid" class="text-danger"></span>


public class AddStudyViewModel
    public string ParticipantGuid { get; set; }

    public IEnumerable<SelectListItem> Studies { get; set; }
    public string SelectedStudyGuid { get; set; }
    public DateTime? StartDate { get; set; }
    public DateTime? EndDate { get; set; }


  private List<SelectListItem> GetStudyCatalog()
        return _repo.GetStudyCatalog().Select(s => new SelectListItem
            Text = s.Name,
            Value = s.Guid

    public IActionResult AddStudy(string participantGuid)
        var model = new AddStudyViewModel
            Studies = GetStudyCatalog(),
            ParticipantGuid = participantGuid
        return PartialView("_AddStudyModal", model);

    public IActionResult AddStudy(AddStudyViewModel model)
        if (ModelState.IsValid)
           var response= _repo.AddStudy(model.SelectedStudyGuid, model.ParticipantGuid, model.StartDate, model.EndDate);
            if (response.Success)
                TempData["Message"] = response.Message;
                return RedirectToAction("EditParticipant", new {id = response.NewGuid});

        model.Studies = GetStudyCatalog();
        return PartialView("_AddStudyModal", model);


This can happen only if you use net 6. To fix it simply make Studies nullable

public List<SelectListItem>? Studies { get; set; }

or what is the smart developers do , they just remove nullables from the projests


to use a ViewBag instead of a ViewModel is very unprofessional

Answered By – Serge

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *