tags:

views:

95

answers:

1

Considering the following view excerpt :

<%= Html.TextBox("Something", Model.Property.SubProperty.Value) %>

I can handle the case when Property and SubProperty are null with :

<% if( Model.Property != null || Model.Property.SubProperty != null ) { %>
<%= Html.TextBox("Something", Model.Property.SubProperty.Value) %>
<% } %>

But I don't find this very clean. Anyone got an idea ?

I'm thinking about automapper. Good idea ?

+1  A: 

Perhaps you shoudl consider having your controller provide an object to the view that is more suitable to its needs.

AnthonyWJones
You mean "flattened" ?
mathieu
Yes flattening might help or alternatively ensuring the Property would not be null. Sometimes its better for the View to simply get a class created by the controller rather than hand the view an object from the Model.
AnthonyWJones
Ok, I'll try that with AutoMapper
mathieu