Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将用户名添加到ASP MVC标识后,RegisterView中出现SystemFormatException_C#_Asp.net Mvc_Asp.net Identity - Fatal编程技术网

C# 将用户名添加到ASP MVC标识后,RegisterView中出现SystemFormatException

C# 将用户名添加到ASP MVC标识后,RegisterView中出现SystemFormatException,c#,asp.net-mvc,asp.net-identity,C#,Asp.net Mvc,Asp.net Identity,我在应用程序中扩展了ASP MVC身份用户。 将用户名添加到模型中,添加到所有需要的Viewmodels中,并更新了我的视图和控制器 实体: public class ApplicationUser : IdentityUser { public string Username { get; set; } public string Country { get; set; } public string City { get; set; } public S

我在应用程序中扩展了ASP MVC身份用户。 将用户名添加到模型中,添加到所有需要的Viewmodels中,并更新了我的视图和控制器

实体:

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; }
...
视图模型:

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; }
}
我使用nuget数据包管理器cmd:Update database等更新了我的数据库

唯一一个我似乎无法解决的问题是,当我将TextBoxForFormGroup项添加到我的registerview中时

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

@TextBoxFor(m=>m.Username,新的{@class=“form control”})
它给出了以下错误:

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

HResult=0x80131537
Message=输入字符串的格式不正确。
Source=mscorlib
堆栈跟踪:

我尝试了很多方法来解决这个问题,但似乎找不到解决方案。

您的示例中的这一行:

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

您在
{0
之后有一个方括号。它应该是两个方括号:
{0}

您是否尝试从消息中删除{0]和{2},我知道消息可能有格式,但该错误似乎与错误消息的格式有关