gpt4 book ai didi

asp.net-mvc-4 - MVC4 : how to use Tuple as model in View and DisplayFor

转载 作者:行者123 更新时间:2023-12-02 04:57:33 25 4
gpt4 key购买 nike

我的第一个 View 是这样开始的:
@model IEnumerable<ToDo4.Models.ToDoItem>
这有效:
<th><br/>
@Html.DisplayNameFor(model => model.Content)<br/>
</th>

当我将 View 更改为使用元组时,DisplayNameFor() 将不起作用。

@model Tuple<IEnumerable<ToDo4.Models.ToDoItem>, ToDo4.Models.ApplicationUser>

    <th>  
@Html.DisplayNameFor(model => model.Item1.Content)
</th>

我不明白为什么 DisplayNameFor() 能够从第一个 @model 中提取 ToDoItem 类型,但当 IEnumerable 位于元组中时却不能。
我忽略了什么?谢谢....

最佳答案

在这里找到答案:MVC Html.DisplayNameFor on a complex model
创建了一个包装类,将 IEnumerable<> 更改为 IList<>,这似乎有效:

<日>
@Html.DisplayNameFor(model => model.Item1[0].Content)

关于asp.net-mvc-4 - MVC4 : how to use Tuple as model in View and DisplayFor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20072738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com