When a users visits my home page and they click the log in button it brings up jquery ui dialog that contains a regular form.
@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @name = "user-login-form", @id = "user-login-form" }))
{
<fieldset style="margin: 10px 0 0 0;">
<label for="name">
Username</label>
<input type="text" name="UserName" id="username" class="text ui-widget-content ui-corner-all" />
<label for="password">
Password</label>
<input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" />
</fieldset>
}
This form exists in a partial view that is part of the index view on the home controller. As you can see it posts to the Logon action in the Account controller. The following is that action.
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl) // rename either the model or the view name field to match.
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
AuthenticationService.SignIn(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
if (MembershipService.IsUserInRole(model.UserName, "ServiceProvider"))
{
return RedirectToAction("Index", "ServiceProvider");
}
return RedirectToAction("Index", "Project");
}
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
// If we got this far, something failed, redisplay form
return View(model);
}
As you can see if the model is not valid it sends you to the LogOn view (not a partial) which is part of the Account controller.
The problem is … whether I fill out the form from the partial or the regular view either way I end up at the /Account/LogOn page with a 500 error. I’ve gone over it a hundred times and I can’t seem to figure out what’s going wrong. The data is correct. The user name and password are validated but I never actually make it to the Index action on the Project controller.
The index action in the Project controller exists and all it does is return View(). The Index.cshtml file does exist. Even if I remove all models and make the page as simple as possible I still end up with the same issue. Staying on the /Account/Logon page with a 500 error instead of making it to /Project/Index.
I have done some searching and did find some stuff about redirecting from ajax etc … and something saying that you shouldn’t redirect from a partial but even from the regular view it’s not working. Not sure if it could be an IIS issue or something? Definitely willing to try anything … been struggling on this for 2 days.
Thanks,
1) 500 Server error means that a script has thrown an error, this is not a broken link like 404 error.So use ‘friendly http errors’, this will give you a more comprehensive description of the error so you can debug the script.
2) Try using Razor syntax in Mvc 3 like below or using Strongly type on view.
3) May be your password property is wrong(it Password not password).
}