Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7609401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:09:45+00:00 2026-05-31T01:09:45+00:00

Good day everybody, I’m having troubles with the display of a data that does

  • 0

Good day everybody,

I’m having troubles with the display of a data that does not always exist.

<div class="display-label">client</div>
<div class="display-field">
  @Model.Contact.client.nomCompteClient
</div>

<div class="display-label">civilite</div>
<div class="display-field">
  @Model.Contact.civilite
</div>

In this code, if @Model.Contact.client.nomCompteClient is not set, I get the following error : Object reference not set to an instance of an object.
But, if every other data is empty, there is no problem, there is just nothing that is displayed.
I don’t understand what I’ve done to set “nomCompteClient” mandatory.

here is my controller :

    Function Details(id As Integer) As ActionResult
        Dim contact As contact = db.contact.Single(Function(c) c.idContact = id)
        Dim meetings = (From d In db.meeting
                        Where d.FK_meet_contact = id
                        Select d).ToList()
        Dim opportunites = (From e In db.opportunite
                          From f In db.transmission_opportunite
                          Where f.FK_trans_cont = id And f.FK_trans_opp = e.idOpportunite
                          Select e).ToList()
        Dim interviews = (From g In db.interview
                          Where g.FK_int_contact = id
                          Select g).ToList()


        Dim model = New ContactDetails With {
            .Contact = contact,
            .Meetings = meetings,
            .Interviews = interviews,
            .Opportunites = opportunites
        }

        Return View(model)
    End Function

Here is the model I’ve used

Public Class ContactDetails
    Public Property Contact As contact
    Public Property Meetings As IEnumerable(Of meeting)
    Public Property Interviews As IEnumerable(Of interview)
    Public Property Opportunites As IEnumerable(Of opportunite)
End Class

Sorry if my english sucks, I’m not a native english speaker.

edit :
I’m not allowed to answer, so I’ll edit with the “solution” I found

I finally fixed it like that :

    <div class="display-field">
    @If Model.Contact.FK_contact_client Then
        @Model.Contact.client.nomCompteClient
        End If
    </div>

FK_contact_client is the FK that refers to the client the contact is working for.

Weren’t there any better possibility?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:09:46+00:00Added an answer on May 31, 2026 at 1:09 am

    Your question doesn’t really has anything to do with ASP.NET MVC. It’s a basic .NET question about object references. You have designed an object hierarchy with properties and sub-properties. In order to be able to access Model.Contact.client.nomCompteClient you need to initialize first the Contact property, and then the client property.

    Here you seem to be fetching the contact from the database:

    Dim contact As contact = db.contact.Single(Function(c) c.idContact = id)
    

    Make sure that in the returned object, the client property is initialized otherwise you cannot use it.

    For example here:

    @Model.Contact.civilite
    

    this displays nothing because the Contact property is not null but the civilite property even if it is null or empty you no longer try to call any method or property on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good morning everybody! (Yeah I know, that not necessary the morning on your side
Good day everybody! Having the following code: template<typename T, typename OutStream = std::ostream> struct
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day, I try to start new Activity from another. But it always crashed.
Good day, all. I know that this is a pretty basic question in terms
Good Day, I have a simple working routine in Perl that swaps two words:
Good day, Stack Overflow. I have a homework assignment that I'm working on this
Good-day, I'm experiencing a very strange event that just started happening. Whenever I press
Good day, Does anyone know if there is a way to determine when all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.