asp.mvc model design

前端 未结 4 1977
鱼传尺愫
鱼传尺愫 2021-01-14 21:21

I am pretty new to MVC and I am looking for a way to design my models.

I have the MVC web site project and another class library that takes care of data access and c

4条回答
  •  感动是毒
    2021-01-14 21:44

    You will likely find differing opinions on this. I will give you mine:

    I tend to, by default, reuse the object. If the needs of the view change and it no longer needs most/all of the data in the business object, then I'll create a separate view. I would never change the business object to suit the view itself.

    If you need most/all of the information in the business object, and need additional data, then I would create a view that holds a reference to the business object and also has properties for the additional data points you need.

    One benefit of reusing the business object is that, depending on the data access technology you are using, you can get reuse out of validation. For isntance, ASP.NET MVC 3 coupled with Entity Framework is nice as they both use the attributes in the System.ComponentModel namespace for validation.

提交回复
热议问题