i am facing a strange situation. I have a Model Document and it has a

List< Child > Childs.

public class Document{
   List< Child > Childs;
}

public class Child{
   int ChilId;
   int GroupIndex;
   string text;
}

When I draw the model in razor I am using a for statement. So every Childs gets paintend properly as a input textbox. I want that the childs are drawed in order, so before passing the model to the view i do a order in the controller to the List

  model.Childs=model.Childs.OrderBy(x=> x.GroupIndex);

If I draw the model and post it with changes it works properly.

The problem comes when I add dinamycally (Js) to the view a new Child element to the Model, and it has errors,(Model not valid) Controller orders the model again, and pass the invalid model to Razor. Inside razor is ordered but when it got painted it doesn´t get ordered like before. The fact that worries me is that i want to draw some header every GroupIndex change like this:

GroupIndex 0
  +Child 
  +Child 
  +Child

 GroupIndex 1
  +Child
  +Child
  +Child

What can i do?Why razor works strange?

Thanks!

Related posts

Recent Viewed