Introduce the blog engine in ASP.NET MVC, where I want strongly typed views. I have a model for BlogPost and a model for comments. A typical page will display a blog post and all these comments on the post. Which object should I go to View ()? Should I create a view model? Maybe I'm misusing this term, but under this I should create a combined model for View () only, something like BlogAndComments? Should my controller create an instance of BlogAndComments and pas that?
Or, should I somehow pass the BlogPost and Comments object into the view?
, . , View Model, , , " ". , , BlogPost ViewData. , , .
, . - "", , , . BlogViewPage, Title, BlogPost List.
, , BlogViewPage, , .
, , .
BL , :
class CommentBO { Guid UserID; string Text; }
BO .
class PostBO { Guid UserID; List<CommentBO> Comments; }
.
class BlogModel { string AuthorName; string BlogTitle; List<PostBO> Posts; }
BO . , . . , , - , - .
. , , , , . , , , . , , . , , . , , , .
In my opinion, if the comments belong to the blog, why not create a collection of comments on the blog model? This makes sense in terms of domain modeling, and the likelihood that the ORM you use will support the lazy loading of this collection, which also simplifies your controller logic.
Source: https://habr.com/ru/post/1706706/More articles:filestream in sql server and c # for aspx - c #выделить выделенный элемент в панели flowlayoutpanel - c#Is there any advanced pop3 class for open source for php? - phpproject management / several versions - version-controlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1706705/how-to-diffmerge-changes-to-a-deployment-project-file&usg=ALkJrhiwhm16OEokFZYwxZuYdJbE-PLJJAC # Generics - an array? - genericsReading custom HttpWebResponse StatusDescription? - restУдаление или удаление строк в таблице назначения пакета SIS - sql-server-2005Size of encrypted data using Triple DES - c #iPhone UITableView missing button-open after clicking Delete when reusing UITableViewCell - iosAll Articles