I am learning a newly created default simple MVC4 web project.
In the index page, I have a link for the user to log on the site with his account. After that he will be redirected to a form to enter new name, new password.
I have this form ready for validation using [Required]. But as sooon as the redirected page is completely loaded, these controls (username and password) were done validated (Field needs be filled in) too.
Here is the code of POST after the user log in with his account
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToCreateUser(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
and here is the method RedirectToCreateUser
private ActionResult RedirectToCreateUser(string url)
{
if (Url.IsLocalUrl(url))
{
return Redirect(url);
}
else
{
return RedirectToAction("CreateNewUser", "Account");
}
}
finally the CreateNewUser method which is for http GET
public ActionResult CreateNewUser(CreateNewUserModel model)
{
return View(model);
}
and another one for http POST which I think hasn’t been accessed yet though.
[HttpPost]
public ActionResult CreateNewUser(CreateNewUserModel model, string url)
{
if (ModelState.IsValid)
{
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true);
WebSecurity.Login(model.UserName, model.Password);
return RedirectToAction("CreateUserSuccess", "Account");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
else
{
}
return View(model);
}
your problem is here
finally the CreateNewUser method which is for http GET
You cannot pass an object as a parameter on a get request. Probably that signature should be
or something similar