1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > mvc中 html是否单选按钮 c# – 如何使用Html.EditorFor在MVC3中渲染单选按钮?

mvc中 html是否单选按钮 c# – 如何使用Html.EditorFor在MVC3中渲染单选按钮?

时间:2020-06-20 10:36:06

相关推荐

mvc中 html是否单选按钮 c# – 如何使用Html.EditorFor在MVC3中渲染单选按钮?

这是我的模特:

[Required]

[Display(Name = "I'm a:")]

public bool Sex { get; set; }

我的编辑模板:

@Html.LabelFor(model => model.RegisterModel.Sex)

@Html.EditorFor(model => model.RegisterModel.Sex)

但是,这将呈现如下:

Soy:

我如何为男性和女性渲染一些漂亮的单选按钮?我的模型必须具有什么数据类型?

编辑:

这是我新的更新代码:

//Model:

[Required]

[Display(Name = "Soy:")]

public Gender Sex { get; set; }

}

public enum Gender

{

Male = 1,

Female = 2

}

//Viewmodel:

Informacion Personal

@Html.LabelFor(model => model.RegisterModel.Nombre)

@Html.EditorFor(model => model.RegisterModel.Nombre)

@Html.LabelFor(model => model.RegisterModel.Apellido)

@Html.EditorFor(model => model.RegisterModel.Apellido)

@Html.LabelFor(model => model.RegisterModel.Sex)

@Html.EditorFor(model => model.RegisterModel.Sex)

@Html.LabelFor(model => model.RegisterModel.Carnet)

@Html.EditorFor(model => model.RegisterModel.Carnet)

//EditorTemplate:

@model GoldRemate.WebUI.Models.Gender

@{

ViewBag.Title = "Gender";

}

当我运行它时,我收到此错误:

The model item passed into the dictionary is null, but this dictionary

requires a non-null model item of type

‘GoldRemate.WebUI.Models.Gender’.

造成这种情况的原因是什么?如何在表单中显示我的枚举值?

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。