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)
{
%>
开发者_如何学Go <%
foreach (var item in Model)
{%>
<%: item.DisplayText %>
<%: item.DisplayText1 %>
<% }%>
<%} %>
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();
精彩评论