ContosoUniversity
ContosoUniversity copied to clipboard
RedirectToActionJson
Hi Jimmy,
I have very straightforward create action in my controller. After creation I want to redirect to the edit action so the user can continue to edit the newly created item. However the RedirectToActionJson doesn't seem to work properly even though stepping through the code the edit action is being called but the redirection to the edit URL still indicates the create action (/SomeAction/Create) when I would have expected /SomeAction/Edit/[new id]
Could it be something to do with some StructureMap "magic" around ending the request (StructureMapScopeModule) because I'm using Autofac?
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateEdit.Command command)
{
var id = _mediator.Send(command);
return this.RedirectToActionJson(c => c.Edit(new CreateEdit.Query { Id = id }));
}
public ActionResult Edit(CreateEdit.Query query)
{
var model = _mediator.Send(query);
return View("CreateEdit", model);
}
What's it look like from the browser in terms of the request?
On Friday, July 22, 2016, Tim [email protected] wrote:
Hi Jimmy,
I have very straightforward create action in my controller. After creation I want to redirect to the edit action so the user can continue to edit the newly created item. However the RedirectToActionJson doesn't seem to work properly even though stepping through the code the edit action is being called but the redirection to the edit URL still indicates the create action (/SomeAction/Create) when I would have expected /SomeAction/Edit/[new id]
Could it be something to do with some StructureMap "magic" around ending the request (StructureMapScopeModule) because I'm using Autofac?
[HttpPost] [ValidateAntiForgeryToken] public ActionResult Create(CreateEdit.Command command) { var id = _mediator.Send(command); return this.RedirectToActionJson(c => c.Edit(new CreateEdit.Query { Id = id })); }
public ActionResult Edit(CreateEdit.Query query) { var model = _mediator.Send(query); return View("CreateEdit", model); }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jbogard/ContosoUniversity/issues/27, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGYMtYBuL-0wdr-dlxS9enVDm1eBNhTks5qYGy_gaJpZM4JSf3N .