视图模型上的 ForEach 订单

发布于 2024-09-28 04:33:58 字数 660 浏览 0 评论 0原文

在 MVC 2 中,我有一个用户控件 - 部分页面如下。

模型在我的机器上有四个记录

id Dtext Dtext1  
1 A, A1  
2 B  B1  
3 C  C1  
4 D  D1  

- 输出如预期的 ID 顺序中所示。

但部署后输出完全奇怪,如下所示。

D  D1  
B  B1  
A, A1  
C  C1  

想知道如何从 ViewModel 发送或检索数据?为什么不在特定的命令中。任何想法。

我已经下载了 MVC 源代码进行调查,但不知道从哪里开始?

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl< MyData>" %>
<% if (Model != null)
   {
%>

    <% 
        foreach (var item in Model)
        {%>
    <%: item.DisplayText %>
        <%: item.DisplayText1 %>
    <% }%>
<%} %>

In MVC 2 I have a user control - Partial page as below.

Model has four records

id Dtext Dtext1  
1 A, A1  
2 B  B1  
3 C  C1  
4 D  D1  

On My machine - Output is as above in the ID Order which is expected.

But after deployment output is totally bizarre something like below.

D  D1  
B  B1  
A, A1  
C  C1  

Would like to know how data is sent or retrieved from ViewModel? Why not in the specific Order. Any idea.

I have downloaded MVC source code for investigation but don’t have any clue where to start?

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl< MyData>" %>
<% if (Model != null)
   {
%>

    <% 
        foreach (var item in Model)
        {%>
    <%: item.DisplayText %>
        <%: item.DisplayText1 %>
    <% }%>
<%} %>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦浮鱼 2024-10-05 04:33:58

无论如何,您应该传递我假设在您的 MyData 内的列表...使用 OrderBy() 在您获取记录的查询上。在您的情况下,请说明您在何处获得记录列表 -

var result=records.OrderBy(i=>i.id).ToList();

You should be passing list I assume inside your MyData anyways...Use OrderBy() on your query that fetched the records.In your case say wherever you get yout list of records-

var result=records.OrderBy(i=>i.id).ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文