6
I am studying ASP.NET and saw the following code snippet:
ViewBag.QtdNovosComunicados =
(from
c in comunicados
where
c.DataCadastro > UsuarioLogado.dtUltimoAcesso
select
c).Count();
I understand I’m creating a new property in the class ViewBag
.
But how will it define this dynamic property? Does . NET do this at runtime? Type problems may occur when I access this property later?
Oops, thank you for that very enlightening answer. In the case where we need to access data from more than one model in the view, as in reports, it is correct to use the viewBag object or would be the case of a Smell code as cited?
– Caique Romero
@Caiqueromero you can create a specific template for the Report View, which has the data filled out from other objects (which may include other templates). I suggest taking a look at composition in object orientation.
– Oralista de Sistemas
All right, I’ll search here, thanks again :)
– Caique Romero