I’m beginner in MVC3, and I want to get a value from an another controller’s method. Here the two methods:
[HttpPost]
public ActionResult Create(TennisClub tennisclub)
{
if (ModelState.IsValid)
{
db.TennisClubs.Add(tennisclub);
db.SaveChanges();
return RedirectToAction("AssignManager");
}
return View(tennisclub);
}
[HttpPost]
public ActionResult AssignManager(Manager manager)
{
}
So, when I’m creating a new tennis club, Immediately I would like to assign a manager to it… For that I need the primary key “ID”.
So my question is: How to get this ID in my “AssignManager” method ? Thanks in advance
You cannot redirect to an action decorated with the
[HttpPost]attribute. That’s not how a redirect works. A redirect means that you are sending a 301 HTTP status code to the client with the new Location header and the client issues a GET request to this new location.So once you remove the
[HttpPost]attribute from your AssignManager action you could pass the id as parameter:and then: