我是 ASP.net MVC 的新手。我现在被卡住了。我扩展了身份模型以包括名字、姓氏、性别等生物数据。
我想让 Gender 呈现为单选按钮,我能够运行应用程序而不会出现任何错误,但它不会提交注册。这个问题是在我将性别从文本框更改为单选按钮后开始的。这是我的代码。
我的模型的一部分:
[Display(Name = "Middle Name")]
[MaxLength(25)]
public string MiddleName { get; set; }
[Required]
[Display(Name = "Last Name")]
[MaxLength(25)]
public string LastName { get; set; }
[Required]
[Display(Name = "Gender")]
public string Gender { get; set; }
我的控制器:
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var member = new MemberInformation
{
Id =
Guid.NewGuid().ToString() + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day +
DateTime.Now.Hour,
FirstName = model.FirstName,
LastName = model.LastName,
MiddleName = model.MiddleName,
Gender = model.Gender,
ContactAddress = model.ContactAddress,
MarialStatus = model.MarialStatus,
Occupation = model.Occupation,
MobilePhone = model.MobilePhone,
RegistrationDate = DateTime.Now,
}
我的观点:
<div class="form-group">
@Html.LabelFor(m => m.Gender, new {@class = "col-md-2 control-label",})
<div class="col-md-10">
@Html.LabelFor(m => m.Gender, "Male")
@Html.RadioButtonFor(Model => Model.Gender, "Male")
@Html.LabelFor(m => m.Gender, "Female")
@Html.RadioButtonFor(m => m.Gender, "Female")
</div>
</div>