i want to perform a database action on login click. So i am using stored procedure for getting the data, but here i am facing some issues regarding model exception.
public ActionResult Login(UserInfo model, string returnUrl)
{
if (ModelState.IsValid)
{
List<UserInfo> loginDetails = dbContext.Database.SqlQuery<UserInfo>
("exec spGetloginUserInfo @username,@password", new SqlParameter("@username", model.username), new SqlParameter("@password", model.password)).ToList();
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
My Model
public class UserInfo
{
public string usertype { get; set; }
public string username { get; set; }
public string password { get; set; }
public bool active { get; set; }
public DateTime lastmodifieddate { get; set; }
public string modifiedby { get; set; }
public bool RememberMe { get; set; }
}
The exception thrown is
An exception of type 'System.Data.Entity.ModelConfiguration.ModelValidationException' occurred in EntityFramework.dll but was not handled in user code
Please let me know where i am doing wrong and also whether my approach is right? And also is there any other way for database interaction other that stored procedure approach.