im new in asp.net mvc. i watch a tutorial and he is using webmatrix. i tried to add column named "IDViewer" in table "UserProfile" in my database created by webmatrix. but then, when i tried to insert some value it returns me an error of "Invalid column name 'Length'." but i did not declare column name "Length" in my code. please check my codes and the images. thank you

Images Link Here. please take a look

The error

My database, i added column named IDViewer

public class Register
{
    [Required(ErrorMessage = "Please provide password", AllowEmptyStrings = false)]
    public string Username { get; set; }
    [Required(ErrorMessage = "Please provide password", AllowEmptyStrings = false)]
    [DataType(System.ComponentModel.DataAnnotations.DataType.Password)]
    [StringLength(50, MinimumLength = 8, ErrorMessage = "Password must be 8 char long.")]
    public string Password { get; set; }
    public string IDViewer { get; set; }
}

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary("", new { @style = "color: red" })
    <label>Username</label>
    @Html.TextBoxFor(m => m.Username, new { @class = "form-control" })
    <label>Password</label>
    @Html.PasswordFor(m => m.Password, new { @class = "form-control" })
    <label>Student ID</label>
    @Html.TextBoxFor(m => m.IDViewer, new { @class = "form-control" })
    @Html.DropDownList("role",roles,"Select Account Type")
    <button class="btn btn-primary">Register</button>
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Register(Register registerdata, string role)
{
    if(ModelState.IsValid)
    {
        try
        {
            WebSecurity.CreateUserAndAccount(registerdata.Username, registerdata.Password, registerdata.IDViewer);
            Roles.AddUserToRole(registerdata.Username,role);
            return RedirectToAction("Index", "Home");
        }
        catch (MembershipCreateUserException)
        {
            ModelState.AddModelError("", "Sorry the username already exists");    
            return View(registerdata);
        }
    }
    ModelState.AddModelError("","Data invalid");
    return View(registerdata);
}

Related posts

Recent Viewed