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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:22:17+00:00 2026-06-06T05:22:17+00:00

I’m having trouble figuring out how to get my navigation property to update with

  • 0

I’m having trouble figuring out how to get my navigation property to update with the Entity Framework. I used a database first approach and set up all appropriate FK relationships. Here’s what the two tables I’m working with look like:

Rate Profile

  • RateProfileID
  • ProfileName

Rate

  • RateID
  • RateProfileID (FK)
  • Several Other Properties I Want to Update

One RateProfile can/will have many Rates. I built my edit page for RateProfile to display editors for the RateProfile Entity and all of it’s associated Rate entities and stuck all of that in a form with a submit button. I can display everything just fine, but my changes will only persist for the model class (RateProfile) and not for its navigation property (Rates).

Below are my views/HttpPost Edit/ Models
In my HttpPost Edit method, you can see my feeble attempt to loop through and Update each record in the navigation property Rates of the model.

@model  PDR.Models.RateProfile

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>RateProfile</legend>

    @Html.HiddenFor(model => model.RateProfileID)
    @Html.HiddenFor(model => model.LoginID)

    <div class="editor-label">
        @Html.LabelFor(model => model.ProfileName)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ProfileName)
        @Html.ValidationMessageFor(model => model.ProfileName)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.isDefault)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.isDefault)
        @Html.ValidationMessageFor(model => model.isDefault)
    </div>
    <div>
        <fieldset>
        <legend>Dime</legend>
        <table>
            <tr>
                <th>
                    Min
                </th>
                <th>
                    Max
                </th>
                <th>
                    Price
                </th>
                <th></th>
            </tr>
        @foreach (var rate in Model.Rates)
        {
            <tr>
                <td>
                    @Html.EditorFor(modelItem => rate.minCount)

                    @Html.ValidationMessageFor(model => rate.minCount)
                </td>
                <td>
                    @Html.EditorFor(modelItem => rate.maxCount)
                    @Html.ValidationMessageFor(model => rate.maxCount)
                </td>
                <td>
                    @Html.EditorFor(modelItem => rate.Amount)
                    @Html.ValidationMessageFor(model => rate.Amount)
                </td>
            </tr>
        }
        </table>
    </fieldset>

    <p>
        <input type="submit" value="Save" />
    </p>
</fieldset>
}

[HttpPost]
    public ActionResult Edit(RateProfile rateprofile)
    {

        if (ModelState.IsValid)

        {
            db.Entry(rateprofile).State = EntityState.Modified;

            foreach (Rate rate in rateprofile.Rates)
            {
                db.Entry(rate).State = EntityState.Modified;
            }
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(rateprofile);
    }

public partial class Rate
{
    public int RateID { get; set; }
    public int RateProfileID { get; set; }
    public string Size { get; set; }
    public decimal Amount { get; set; }
    public int minCount { get; set; }
    public int maxCount { get; set; }
    public int PanelID { get; set; }

    public virtual Panel Panel { get; set; }
    public virtual RateProfile RateProfile { get; set; }
}

public partial class RateProfile
{
    public RateProfile()
    {
        this.Rates = new HashSet<Rate>();
    }

    public int RateProfileID { get; set; }
    public string ProfileName { get; set; }
    public int LoginID { get; set; }
    public bool isDefault { get; set; }

    public virtual Login Login { get; set; }
    public virtual ICollection<Rate> Rates { get; set; }
}
  • 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-06T05:22:18+00:00Added an answer on June 6, 2026 at 5:22 am

    You change the foreach into for statement and try whether the model binding is working fine or not.

    @for (var int i = 0; i < Model.Rates; i++)
    {
        <tr>
            <td>
                @Html.EditorFor(modelItem => Model.Rates[i].minCount)
                @Html.ValidationMessageFor(model => Model.Rates[i].minCount)
            </td>
            <td>
                @Html.EditorFor(modelItem => Model.Rates[i].maxCount)
                @Html.ValidationMessageFor(model => Model.Rates[i].maxCount)
            </td>
            <td>
                @Html.EditorFor(modelItem => Model.Rates[i].Amount)
                @Html.ValidationMessageFor(model => Model.Rates[i].Amount)
            </td>
        </tr>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a reasonable size flat file database of text documents mostly saved in
I'm making a simple page using Google Maps API 3. My first. One marker
I have a view passing on information from a database: def serve_article(request, id): served_article

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.