首页 > Web开发 > 详细

@Html.DropDownList

时间:2020-04-04 12:56:14      阅读:61      评论:0      收藏:0      [点我收藏+]

page

 @Html.DropDownList("ID", Model.SystemParameterList)

 

ViewModel:

public IEnumerable<SelectListItem> SystemParameterList
{
get
{
SystemParameterBLL bll = new SystemParameterBLL();
IList<SystemParameter> liPa = bll.GetList();
List<SelectListItem> li = new List<SelectListItem>();
foreach (SystemParameter item in liPa)
{
SelectListItem listItem = new SelectListItem();
listItem.Text = item.Name;
listItem.Value = item.Id;
li.Add(listItem);
}
return li;

}
}

 

Controller :

[HttpPost]
public IActionResult SetComponentProperty(ComponentPropertyViewModel vm)
{
return this.SetComponentProperty(vm.ComponentId, vm.OrderId);
}

这样Post后台Controller 时,vm.ID就是下拉框的Value.

注:后台想获取获取对应Text ,我没找到啥办法。准备把text和value都放到value中,后台再去拆开来(如:name#123)

 

@Html.DropDownList

原文:https://www.cnblogs.com/sportdog/p/12631232.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!