public ActionResult Details(int? id) { var dbo = new DrugBusiness(); DrugModel dm = dbo.DetailsMethod(id); DateTime drug_expdate = dbo.GetAll().Find(x => x.DrugId == id).ExpiryDate; DateTime now = DateTime.Today; var days = drug_expdate - now; if(drug_expdate<=now) { ViewBag.msg = "The Drug has expired"; } else { ViewBag.msg = "This Drug expires in " + days.Days + "Days"; } return PartialView(dbo.DetailsMethod(id));
it says "{"Object reference not set to an instance of an object."}"
int?
if(id.HasValue) { // do something } else { // id is NULL, do something else }
DateTime drug_expdate = dbo.GetAll().Find(x => x.DrugId == id).ExpiryDate; DateTime now = DateTime.Today; if (drug_expdate != null) { var days = drug_expdate - now; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)