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 8213585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:10:12+00:00 2026-06-07T11:10:12+00:00

I can’t figure out how to have navigation properties for my model (EF4) not

  • 0

I can’t figure out how to have navigation properties for my model (EF4) not be null after I post. I have the same problem on several basic pages.

i.e. I have a table
Estimate
with a foreign key of
LoginID (from the Login table).

In my HTTPGet Edit method, I find the specific estimate I want:

Estimate estimate = db.Estimates.Find(id)

From here I can access the Login navigation property and any of the properties of that record from the Login table.

I pass this estimate as the model for my strongly typed view. When my HTTPPost Edit method gets called (and the model is passed to it as a parameter), my Login navigation property is null and I can’t access anything in it. I can get around it of course because I do have the LoginID field in my estimate class, but it feels really clunky and like I’m missing out on a key benefit of the entity framework.

I have this same problem on multiple pages where I’m passing a model with a navigation property to my view and the view is returning the model with a null navigation property.

Below is an example of the code I was having trouble with:

    [HttpPost]
    public ActionResult Edit(Estimate estimate)
    {

        var test = estimate.Login.CompanyProfileID;
        ...

I can access Model.Login and all of it’s properties just fine in the view, so I know it’s getting passed to the view properly. It just doesn’t pass the navigation property back to the controller when my form submits.

  • 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-06-07T11:10:15+00:00Added an answer on June 7, 2026 at 11:10 am

    What is happening is that MVC uses something called ‘Model Binding’, which matches all the fields that POST passes in the page request to matching properties of the parameter of your action.

    So, if the property is not included in the input fields in the POST page, it will not be bound to the parameter in your POST action, and thus, will be null.

    So, you could either include a hidden field for every property in Login, e.g.

    @Html.HiddenFor(m => m.Login.ID)
    @Html.HiddenFor(m => m.Login.Name)
    

    Or, just do as you describe in your workaround – ie requery the database based on the Id. Although this may seem clunky, this is a perfectly valid way of doing things, as it avoids having to pass hidden fields around all over the place.

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

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can someone help me out please, as google is not providing the answers. I've
Can a Backbone.js View have a Model and a Collection ? The reason I
Can I order my users in the database, so I don't have to say
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can some one Guide me to work with these things... What is Model popup
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can't work out a way to make an array of buttons in android. This

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.