ContosoUniversity icon indicating copy to clipboard operation
ContosoUniversity copied to clipboard

RedirectToActionJson

Open TDK1964 opened this issue 7 years ago • 1 comments

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);
}

TDK1964 avatar Jul 22 '16 07:07 TDK1964

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 .

jbogard avatar Jul 22 '16 13:07 jbogard