我对MVC很新,我正在努力创建一个注册页面,让用户注册最多5个“字符”。我正在设置它,以便该区域是一个下拉列表,字符名称是一个文本框字段。以下是我为一个角色设置工作的示例,但我希望允许用户注册多个并将其全部链接到他们的帐户:
@using (Html.BeginForm("RegisterUser", "Account"))
{
@Html.TextBoxFor(m => m.UserName, new { data_bind = "value: Name:", @class = "form-control app-fill-lightgray app-border-darkgray fieldInput", @placeholder = "Username" })
@Html.TextBoxFor(m => m.CharacterName, new { data_bind = "value: Name:", @class = "form-control app-fill-lightgray app-border-darkgray fieldInput", @placeholder = "Charactername" })
@Html.DropDownListFor(m => m.Server, Model.Server, new { data_bind = "value: Name:", @class = "form-control app-fill-lightgray app-border-darkgray fieldInput" })
@Html.PasswordFor(m => m.Password, new { data_bind = "value: Name:", @class = "form-control app-fill-lightgray app-border-darkgray fieldInput", @placeholder = "Password" })
@Html.PasswordFor(m => m.ConfirmPassword, new { data_bind = "value: Name:", @class = "form-control app-fill-lightgray app-border-darkgray fieldInput", @placeholder = "Confirm Password" })
<button type="submit" id="LoginButton" class="btn btn-lg btn-primary btn-block">Register</button>
</div>
</fieldset>
}
这是Register.cs模型:
public class Register
{
public Register()
{
this.Servers = new SelectList(
new List<Object>{
new { value = 0 , text = "na" },
new { value = 1 , text = "eu" },
},
"value",
"text",
0);
}
[Required(ErrorMessage = "Username Required:")]
public string UserName { get; set; }
[ValidSummonerAttribute(ErrorMessage="Invalid Summoner Name")]
//[Required(ErrorMessage = "Character Name Required:")]
public string CharacterName { get; set; }
public int Server { get; set; }
[Required(ErrorMessage = "Password Required")]
[DisplayName("Password:")]
[RegularExpression(@"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^(.{8,})$", ErrorMessage = "Password must be at least 8 characters and contain one numeric character")]
public string Password { get; set; }
[System.Web.Mvc.Compare("Password", ErrorMessage="Passwords must match")]
[Required(ErrorMessage = "Confirm Password Required:")]
[DisplayName("Confirm Password:")]
[RegularExpression(@"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^(.{8,})$", ErrorMessage = "Password must be at least 8 characters and contain one numeric character")]
public string ConfirmPassword { get; set; }
}
}
我真正想要的是设置一个像这样的角色信息对象:
public class CharacterInfo
{
int Server { get; set; }
string CharacterName { get; set; }
}
为模型提供List字符的属性。
我被困住了,似乎无法找到办法,任何帮助或示例都非常感谢!
提前致谢!