SystemFormatException in RegisterView after adding Username to ASP MVC Identity

1

I extended the ASP MVC Identity User in my application. Added Username to the model, to all the Viewmodels where it is necesary and also updated my views and Controllers.

Entity:

public class ApplicationUser : IdentityUser
{
   public string Username { get; set; }
   public string Country { get; set; }
   public string City { get; set; }       
   public System.DateTime? BirthDate { get; set; }
...

ViewModel:

public class RegisterViewModel : BaseViewModel
{
    [Required]
    [EmailAddress]
    [Display(Name = "Email")]
    public string Email { get; set; }

    [Required]
    [StringLength(30,ErrorMessage = "The {0] must be at least {2} characters long.",MinimumLength = 6)]
    [Display(Name = "Username")]
    public string Username { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}

I updated my database using the nuget packet manager cmd : Update-Database, etc..

The only problem I can't seem to fix is when i add a TextboxFor formgroup item to my registerview

<div class="col-md-8">
    @Html.TextBoxFor(m => m.Username, new { @class = "form-control" })
</div>

It gives following error :

System.FormatException occurred
HResult=0x80131537
Message=Input string was not in a correct format.
Source=mscorlib
StackTrace:
<Cannot evaluate the exception stack trace>

I tried a lot of things to fix this but I can't seem to find a solution.

c#
asp.net-mvc
asp.net-identity
asked on Stack Overflow May 12, 2017 by Jelman • edited May 12, 2017 by Igor

1 Answer

1

This line from your sample:

[StringLength(30,ErrorMessage = "The {0] must be at least {2} characters long.",MinimumLength = 6)]

You have a square bracket after {0. It should be both curly brackets: {0}.

answered on Stack Overflow May 13, 2017 by trailmax

User contributions licensed under CC BY-SA 3.0