I want to send an empty list from the controller to the view, populate it, and then send it back to the controller. I'm unsure how to do this without creating this exception
System.NullReferenceException: 'Object reference not set to an instance of an object.
Basically my question is, how do I default the list in my model of be empty?
Model
public class AuditViewModel
{
public string Domain { get; set; }
public string Level { get; set; }
public string NEWS { get; set; }
public string Auditor { get; set; }
public int PatientID { get; set; }
}
public class AuditDetail
{
// I want to send this list as empty when page loads
public List<AuditViewModel> AuditDetails { get; set; }
}
This is my controller:
public class HomeController : Controller
{
public ActionResult Index()
{
Models.AuditDetail ad = new Models.AuditDetail();
return View(ad);
}
public ActionResult Audit()
{
return View();
}
}
View
@{ int i = 0; foreach (var item in Model.AuditDetails.ToList()) }