【发布时间】:2021-11-12 00:31:15
【问题描述】:
我的视图页面中有一个下拉菜单。由于下拉列表只有两个值并且不会更改,因此我们决定创建静态下拉列表。
@Html.DropDownList("RelationshipWithFather", new List<SelectListItem>()
{
new SelectListItem() { Text= "son", Value = "son" },
new SelectListItem() { Text= "daughter", Value = "daughter" }
}, "relationship...", new { @class = "form-control" })
如何传递这个RelationshipWithFather下拉选择的值来创建控制器方法。
public ActionResult Create(PatientInfo vdm_)
{
if (ModelState.IsValid)
{
PatientInfo vdm = new PatientInfo();
vdm.relationshipWithPatient = // selected value of RelationshipWithFather
}
}
我必须将所选下拉列表的值设置为模型类的relationshipWithPatient 属性。
【问题讨论】:
-
如果您查看文档,您会看到 SelectListItem 具有属性 Selected。 docs.microsoft.com/pl-pl/dotnet/api/…
标签: asp.net asp.net-mvc asp.net-mvc-4