I'm new to MVC3 and have run into a little problem. I've scoured the internet and covered topics like complex model binding, etc. to no avail. If this is a simple question, I apologize in advance.
Here's what my classes look like:
public class Vod
{
public virtual int id {get; set;}
public virtual string myname {get; set;}
public virtual Metadata Metadata {get; set;}
}
public class Metadata
{
public System.Datetime? dtmCreationDate {get; set;}
public string strCreatedBy {get; set;}
public string strModifiedBy {get; set;}
public System.Datetime? dtmModifiedDate {get; set;}
}
And here's a sample of my edit controller:
[HttpPost]
public ActionResult Edit(Vod vod)
{
if (ModelState.IsValid)
{
db.Entry(vod).State = EntityState.Modified;
vod.Metadata.strModifiedBy = "modified";
vod.Metadata.dtmLastModified = DateTime.Now;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(vod);
}
My problem is trying to figure out how to set these default values in my controller whenver I create or edit a record and save the values in my database. Right now the code above does not work because I'm not doing it correctly (Object reference not set to an instance of an object.)