1
其控制器方法。 它返回空值。 有什麼建議。如何在數據庫中創建不同實體類的對象和存儲記錄MVC4
[HttpPost]
public ActionResult CreatBranch()
{
if (ModelState.IsValid)
{
var contactinfo = new ContactInfo();
db.ContactInfo.Add(contactinfo);
db.SaveChanges();
var contctid = contactinfo.ContactID;
var addressinfo = new Address();
db.Address.Add(addressinfo);
db.SaveChanges();
var addid = contactinfo.ContactID;
var branchInfo = new Branch { ContactID = contctid, AddressID = addid, CreatedDate = DateTime.Now, CreatedBy = Convert.ToInt32(Session["UserID"]), UpdatedBy = Convert.ToInt32(Session["UserID"]) , UpdatedDate = DateTime.Now};
db.Branches.Add(branchInfo);
db.SaveChanges();
return RedirectToAction("Index");
}
return RedirectToAction("Index");
}
//int contact id returns int value, int add also returns an int value. but remaining attributes are passing null values .