jeudi 5 février 2015

INSERT into two separate tables using ADO.Net


I am creating a tracking application to keep track of some server and their build info. I want the user to fill out one single form that then performs a INSERT into two separate tables. Here is my code, but it only populates the "Server" table and not the "System_Build_Information" table. I have tried also changing the Bindings and even leaving them out all together. This code by the way is from my Server controller



[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Server_Name,Server_Role,Server_OS")] Server server,
[Bind(Include = "Model")] System_Build_Information sys)
{
if (ModelState.IsValid)
{
db.Servers.Add(server);
db.System_Build_Information.Add(sys);
db.SaveChanges();
return RedirectToAction("Index");
}

ViewBag.Server_Role = new SelectList(db.Server_Roles, "Id", "Server_Role", server.Server_Role);
ViewBag.Server_OS = new SelectList(db.Operating_System, "Id", "Operating System", server.Server_OS);
string[] environments = new string[] { "Virtual", "Physical" };
ViewBag.Environments = new SelectList(environments);
return View(server);
}




Aucun commentaire:

Enregistrer un commentaire