Reputation: 7299
I have an action that redirect to another action:
public ActionResult Create(Score score)
{
score.DateOfSubmit = DateTime.Now.Date;
obj.AddNewScore(score);
obj.Save();
return RedirectToAction("Index", "Score");
}
I want to pass an id to index action in last line .so how can pass an id to index action .
Upvotes: 3
Views: 94
Reputation: 62498
Do like this:
public ActionResult Create(Score score)
{
score.DateOfSubmit = DateTime.Now.Date;
obj.AddNewScore(score);
obj.Save();
return RedirectToAction("Index", "Score", new {id=score.Id});
}
and in Index
action do like this:
public ActionResult Index(int id)
{
return View();
}
Upvotes: 2
Reputation: 942
return RedirectToAction("Index", "Score", new { id = score.Id });
Upvotes: 2