I am absolute beginner in C#, ASP.NET and MVC2 and this means that I just might be missing something exceptionally basic. I tried to search for it, but here again, I failed to come up with the proper incantations for neither Google not StackOverflow, so here comes the question:
I am trying to create a basic controller with two actions:
[HttpPost]
public ViewResult Create(CustomerCreateData data)
{
CustomerRecord cr = //create customer record from input data...
return RedirectToAction("Details");
}
public ViewResult Details(int id)
{
CustomerRecord cr = // load customer record with specified id...
return View(cr);
}
My idea is thet after successful POST /Customer/Create the user would be redirected to GET /Customer/Details/42 where 42 is id of the newly created customer record.
What is the proper incantation for this in ASP.NET MVC2
PS – I’ve seen countless examples of redirecting to "Index" action, but that is not quite enough.
You can pass data to the
RedirectToActionmethod:This is assuming you either have a defined route, e.g.
Customer/Details/{id}or that you still have the default route{controller}/{action}/{id}.