So I post to the controller action below and I would like to "path" to this Car object's Client. When I attempt to do this, however, I get a
Null Reference Exception (Object reference not set to an instance of an object) error.
For some reason, Client is null.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ClientID,Name")] Car myCar)
{
if (ModelState.IsValid)
{
db.myCars.Add(myCar);
db.SaveChanges();
//why is Client null here (Null Exception)?
myCar.Client.UpdateLastModified();
return RedirectToAction("Details", "Cars", new { id = myCar.ClientID });
}
}
Is there any way to make this work? Also, if anyone could explain why this is happening, it would help me a great deal.
Thank you in advance.
edit: I'm using Linq-to-SQL, MVC 5, EF 6