Best way to filter domain objects for json output in an ASP.NET MVC application

后端 未结 6 1247
温柔的废话
温柔的废话 2020-12-05 20:59

If I\'m rendering a regular view in asp.net mvc the only domain object properties that show up in my page the ones I specifically write out. For example:

<         


        
6条回答
  •  心在旅途
    2020-12-05 21:53

    Please use a view model. A view model is an object that the UI uses to represent your domain objects on the screen. Each screen has its own view model.

    When you make your view model, which is a DTO, which is a flattened, null-safe projection of domain objects, do not map properties you do not wish to be displayed on the screen.

    Serialize the view model, not your domain object.

提交回复
热议问题