It is not uncommon to want to call action in another controller. This is just a quick sample of calling another controller, setting a Boolean value, and committing the changes.
[HttpPost]
public ActionResult Edit(MyController1 ctrl1, int someId)
{
if (ModelState.IsValid)
{
db.MyController1.Add(ctrl1);
db.SaveChanges();
//Now update the value of another item
OtherController ctrl2 = db.OtherController.Find(someId);
ctrl2.SomeBooleanField = true;
db.Entry(ctrl2).State = EntityState.Modified;
db.SaveChanges();
}
return View(ctrl1);
}
Share This To :
0 comments:
Post a Comment