Two models in one view in ASP MVC 3

后端 未结 12 1876
日久生厌
日久生厌 2020-11-22 13:55

I have 2 models:

public class Person
{
    public int PersonID { get; set; }
    public string PersonName { get; set; }
}
public class Order
{
    public int         


        
12条回答
  •  囚心锁ツ
    2020-11-22 14:37

    If you are a fan of having very flat models, just to support the view, you should create a model specific to this particular view...

    public class EditViewModel
        public int PersonID { get; set; }
        public string PersonName { get; set; }
        public int OrderID { get; set; }
        public int TotalSum { get; set; }
    }
    

    Many people use AutoMapper to map from their domain objects to their flat views.

    The idea of the view model is that it just supports the view - nothing else. You have one per view to ensure that it only contains what is required for that view - not loads of properties that you want for other views.

提交回复
热议问题