I need to display the registration form and login form on the home page.
If validation fails on these two forms, I need to display proper errors on the home page.
But if there was no error, the user must be redirected to the secured Dashboard.
To accomplish this, I am using child action
on the home page like this:
@Html.Action("Register", "Membership")
It work perfectly as expected if there are any errors, as it is able to re-render
the partial view
with the proper model
that has validation state
information.
But if there was no error, when it tries to redirect, it throws an error stating that:
Child actions are not allowed to perform redirect actions.
Is there any way around this? I am sure there is a way to put registration and login forms on the homepage. Most probably I don't know since I am quite new to ASP .Net MVC.
Could you point me in the right direction here?
One way to do this is to use ajax forms for the login and registration bits and, instead of returning a RedirectResult when the submission is valid, return some json which a bit of client-side script will watch out for and use to do a redirect for you.
Here's a simplified example.
Controller:
Home page 'Index' view:
Registration form 'Register' partial view: