I have a HomeController with an Index action that shows the Index.aspx view. It has a username/password login section. When the user clicks the submit button, it POSTs to a Lo
You could call the action directly, but the client side will not have its URL changed. So instead of calling RedirectToAction
you could call the Index()
method of the HomeController
class directly.
HomeController c = new HomeController();
c.ViewData = this.ViewData;
return c.Index(data);
The one is a bit tricky. Maybe you will have to set other things as well apart from ViewData
which is needed for ModelState
.
You could as well use TempData
dictionary and fill it with whatever data you want and use that.
The simplest one where you provide full path to the view
return View("~/Views/Home/Index.aspx", data);
If we look at how other sites do this kind of scenario. Take for instance Twitter (As @David says Facebook apparently does it the same). You can sign in from the Home/Index
action (so to speak if it was developed using Asp.net MVC). But when login fails it displays a separate login page, that displays validation errors. In your case it would be Account/SignIn
. Which would make sense and you could directly return its view with validation errors. When everything would be ok, you'd do it as you do it now. Redirect back to Home/Index
.