Using RenderAction() and posting back to sub-controller action

1k Views Asked by At

I have parent view that also renders sub-controller action using RenderAction() (that returns a PartialView). An example is a front page with Login partial view (inputs: username, password, remember and action: login)

Execution process

  1. GET for Home/Index - also displays my login control that has its login pointing to sub controller User/Login
  2. User enters credentials and clicks login
  3. POST for User/Login - checks credentials and returns ???

Problem

How do I return back to parent view from my sub controller action User/Login?
My sub controller's partial view can be rendered any page, so I can't just easily return result of parent controller action like:

return new HomeController().Index();

So how should I process my sub controller action and its partial view?

EDIT

I could post back to my sub-controller action with additional data of the parent route, but I also populate data in my sub-controller action. In my example I have to display that someone's credential weren't valid. A redirect would lose these...

1

There are 1 best solutions below

2
On BEST ANSWER

Instead of posting to /User/Login for performing the login, append a return url, so you would end up with /User/Login?returnUrl=/Home/Index (url encoding might change that a bit)

If returnUrl is set in the querystring, the action for /User/Login should just return a redirect action back to that returnUrl.

Sorry if that was a little unclear