views:

80

answers:

2

If you see at the top of an ASP.NET MVC view:

<% var dto = (MyDto)Model; %>

...is something wrong? It doesn't feel right to me...

+5  A: 

You should not need to cast the type in this way for a strongly typed view. If the view inherits from ViewPage<MyDto> then the Model property will be of type MyDto.

If the view is not strongly typed then the Model property is of type object so you would need to cast it.

It makes sense to use a strongly typed view in this case though

Charlie
+1  A: 

The question is: Is it good to store DTO objects as the model for View? My answer is: it's depends. DTO should have only one behavior: storing data. So when you using DTO object only for displaying it on View: then it's OK.

View Model is designed to store more compliated objects that contains multiple behaviors, but there is no fault to store DTO's.

dario
Can you give an example when the object sent to the view needs more complex functionality?
Ben Aston
For example: some ActiveRecord object
dario