asp.net-mvc-3 – asp.net mvc 3 razor从IEnumerable获取一个元
发布时间:2020-12-15 20:38:29 所属栏目:asp.Net 来源:网络整理
导读:我的视图模型(LIST)看起来像这样: public class ConversationModel { public int ID { get; set; } public string Body { get; set; } public DateTime Datetime { get; set; } public string Username { get; set; } public string ImgUrl { get; set; } p
我的视图模型(LIST)看起来像这样:
public class ConversationModel { public int ID { get; set; } public string Body { get; set; } public DateTime Datetime { get; set; } public string Username { get; set; } public string ImgUrl { get; set; } public string ToUserID{ get; set; } } 这是我的看法 @model IEnumerable<NGGmvc.Models.ConversationModel> 如何获取当前位置的ToUserID?这样的东西 @model [0] .ToUserID 谢谢 解决方法
你应该能够做到:
@Model.First().ToUserID 注意,你可能想检查枚举中是否有任何项目,如果没有,那么First()将返回null (请注意,由于您的问题中有@Model [0],我假设您是专门设法获取第一个值,我可能会错误的使用这个选项,Jakub的答案应该排除您的!) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 绕过路径遍历过滤器
- asp.net – WebForms:MasterPages中的动态(或绝对)脚本标记
- 在Asp.net中运行外部可执行文件的内存限制
- 经典ASP中的会话
- asp.net-mvc – MVC WebApi不使用AutofacWebApiDependencyR
- asp.net-mvc – 创建一些东西@using(Html.BeginForm())助手
- asp.net – 无法访问已关闭的文件
- asp.net-mvc-3 – 带有重音IE8的ASP MVC3 FileResult – 被
- asp.net-mvc – 在MVC3中扩展ClaimsIdentity
- 如何在ASP.NET中实现浮动许可证?
推荐文章
站长推荐
- asp.net – web.config角色和用户名是否允许空格
- ASP.NET MVC或ASP.NET MVC2 RC2 – > RTM
- Tensorflow Mnist数据集
- asp.net-mvc – 为什么在ASP.NET MVC 3中,默认路
- asp.net-mvc – 在空项目中缺少类型Mono.Web.Uti
- asp.net-mvc – 在ASP.Net MVC视图中显示/隐藏链
- asp.net – iTextSharp单位
- asp.net – IE 11中的报表查看器打印按钮
- asp.net-mvc – 使用BootstrapValidator与MVC Da
- ASP.NET MVC 3和ASP.NET MVC 4剃刀语法更改?
热点阅读