views:

37

answers:

1

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 %>
    <% }%>
<%} %>
+2  A: 

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();
Misnomer
i know how to resolve this problem but i want to know why on one machine data is displayed in ascending order but on other machine Not? Why not in the specific Order on every machine. Any idea
swapneel
using IEnumerable Inherits="System.Web.Mvc.ViewUserControl<IEnumerable < MyData>>" %>
swapneel
It is the way you would fetch records from database...nothing to do on the `view` side of it..I am not sure what exactly may cause it..
Misnomer