[英]pass the selected value of Html.DropDownList to controller
I have a drop down in my view page.我的视图页面中有一个下拉菜单。 Since the drop down has only two values and it will not change so we decided to create static drop down.
由于下拉列表只有两个值并且不会更改,因此我们决定创建静态下拉列表。
@Html.DropDownList("RelationshipWithFather", new List<SelectListItem>()
{
new SelectListItem() { Text= "son", Value = "son" },
new SelectListItem() { Text= "daughter", Value = "daughter" }
}, "relationship...", new { @class = "form-control" })
Try to use DropDownListFor尝试使用 DropDownListFor
@model PatientInfo
....
@{
var items= new List<SelectListItem>()
{
new SelectListItem() { Text= "son", Value = "son" },
new SelectListItem() { Text= "daughter", Value = "daughter" }
};
}
@using (Html.BeginForm()) {
@Html.DropDownListFor (model=>model.relationshipWithPatient, items , "relationship...", new { @class = "form-control" })
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.