asp.net-mvc-3 – HTML.DropdownList – 文本字段显示多列的值
发布时间:2020-12-16 09:36:56 所属栏目:asp.Net 来源:网络整理
导读:我有一个这样的下拉列表: @Html.DropDownList("DeliveryOptions",(IEnumerableSelectListItem)ViewData["DeliveryOptions"]) 这从控制器动作获取其数据,如下所示: var options = context.DeliveryTypes.Where(x = x.EnquiryID == enqId);ViewData["Deliver
我有一个这样的下拉列表:
@Html.DropDownList("DeliveryOptions",(IEnumerable<SelectListItem>)ViewData["DeliveryOptions"]) 这从控制器动作获取其数据,如下所示: var options = context.DeliveryTypes.Where(x => x.EnquiryID == enqId); ViewData["DeliveryOptions"] = new SelectList(options,"DeliveryTypeId","CODE" + " - " + "DeliveryPrice"); 我想让我的下拉列表在其文本字段中显示CODE DeliveryPrice,例如:’TNTAM – 17.54’但是我收到以下错误: DataBinding: 'MyApp.Models.DeliveryTypes' does not contain a property with the name 'CODE - DeliveryPrice'. 我的DeliveryType模型如下所示: [Key] public int DeliveryTypeId { get; set; } public string CODE { get; set; } public decimal DeliveryPrice { get; set; } 解决方法
您可以使用匿名类型:
var options = context.DeliveryTypes .Where(x => x.EnquiryID == enqId) .Select(x => new { Value = x.DeliveryTypeId,Text = x.CODE + " - " + x.DeliveryPrice }); ViewData["DeliveryOptions"] = new SelectList(options,"Value","Text"); 或者创建一个可以重用的特定CustomSelectListItem类,其中包含Value和Text属性,您可以在这种情况下重复使用它们. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET MVC2与实体框架4 – AsEnumerable()或ToList()在存
- 向ASP.NET Core迁移
- asp.net-mvc – 从ASP.NET MVC中的部分视图中删除逻辑
- asp.net-mvc – ASP.NET MVC路由和静态数据(即图像,脚本等)
- ASP.Net自定义会话状态管理
- asp.net-mvc-5 – 同一域中的Web API 2项目和MVC 5网站项目
- asp.net – MVC3何时使用区域?
- asp.net – bin目录中是否存在.pdb文件会对性能产生负面影响
- C#_.NetFramework_Web项目_NPOI_EXCEL数据导入
- 从ASP.Net获取UserID登录控件LoggedIn事件
推荐文章
站长推荐
- asp.net-mvc-4 – ASP.NET MVC4模型绑定
- asp.net:DetailsView控件不解释html
- ms-access – ASP奇怪的未指定错误 – 80004005
- asp.net – PolicyException:无法获取所需的权限
- asp.net core webapi文件上传
- asp.net-mvc – 为什么MVC控制器必须在其类名上具
- Mvc项目架构分享之项目扩展 架构搭建
- asp.net-mvc – angularjs和mvc5之间通信的最佳方
- ASP.NET Web API项目自定义接口路由和HTTP请求方
- asp.net-mvc – ASP.NET MVC:HTTPContext和依赖
热点阅读