0

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Ok, I'll try that with AutoMapper

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.