Deeptechtons
Deeptechtons

Reputation: 11125

Maintain URL after Post in asp.net MVC

Fairly new to asp.net mvc I don't have knowledge to change the way certain things work. Here is one of them

  1. Controller Action Index displays a Login page

  2. Controller Action Login with [HttpPost] takes the model and validates it

In the case, validation fails the URL seems to be set at http://blah_blah/Users/Login ( which when requested causes 404 since there is no Login action on the controller)

So is creating a Login action only way to solve problem or any other solutions i got ?

Upvotes: 2

Views: 4881

Answers (3)

VJAI
VJAI

Reputation: 32768

Why can't you rename the Login action to Index.

public ActionResult Index()
{
   return View();
}

[HttpPost]
public ActionResult Index(LoginModel model)
{
   return View();
}

or

you can use ActionName attribute

[HttpPost, ActionName("Index")]
public ActionResult Login(LoginModel model)
{
   return View();
}

Upvotes: 7

dove
dove

Reputation: 20674

Try this:

return RedirectToAction("Index", "User", new { returnUrl, errorMessage, etc });

Upvotes: 0

Kirill Bestemyanov
Kirill Bestemyanov

Reputation: 11964

you have to return View("Index");

Upvotes: 1

Related Questions