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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:44:16+00:00 2026-05-17T18:44:16+00:00

I have a form that creates a new brand. The user chooses a name,

  • 0

I have a form that creates a new brand. The user chooses a name, image, and website url for the brand and hits submit. The edit scenario works the same way. The issue I’m having is when creating a new brand, the correct imageId is being posted, and right up to SaveChanges() in my action its correct. When I check the new row in the database, the ID has been doubled and then some. (for example if I submit 37, the database changes it to 78, 38 to 80 etc.) I’m stumped as to why this is happening. Here’s my action:

    [HttpPost]
    public ActionResult NewBrand(Brand brand)
    {
        try
        {
            brand.BrandName = Request.Form["BrandName"];
            brand.BrandImageId = int.Parse(Request.Form["Image.ImageId"]);
            brand.BrandWebsite = Request.Form["BrandWebsite"];

            _entities.Brands.AddObject(brand);
            _entities.SaveChanges();

            return RedirectToAction("Brands");
        }
        catch (Exception ex)
        {
            var script = "alert(" + ex.Message + ")";

            return JavaScript(script);
        }
    }

And heres an example POST from firebug

Parametersapplication/x-www-form-urlencoded
BrandName    Sample Brand
BrandWebsite    www.somewebsite.com
Image.ImageId    37
Source
Content-Type: application/x-www-form-urlencoded Content-Length: 72 
BrandName=Sample+Brand&Image.ImageId=37&BrandWebsite=www.somewebsite.com

I am using the entity framework and built my database using the wizards in visual studio. My brands table has the foreign key ImageId and i have an image table with the primary key ImageId, they have a one to many relationship. Any ideas?

edit

I created the entity framework object by right-clicking my models folder and adding a new .edmx file. And then I right clicked in the design view and hit “update from database” and it created a model from the tables I created. I haven’t done any special configuration or setup beyond this, nor am I using the repository pattern (yes, that means I have data access code in my controllers, I am refactoring this weekend) which I learned after starting this project.

_entities comes from this line at the top of the controller

private MHNHubEntities _entities = new MHNHubEntities(); 
  • 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-17T18:44:17+00:00Added an answer on May 17, 2026 at 6:44 pm

    I eventually solved the issue by looking up the image using the image id and then assigning that image to the BrandImage property, instead of assigning the ID to BrandImageID, which was adding a new, blank Image to the database.

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

Sidebar

Related Questions

I have a small form inside a table. POSTing that form creates a new
I have a form that uses jQuery to submit an ajax post and it
We have a form that allows a user to filter a list with by
I have a VERY simple windows form that the user uses to manage Stores.
I have this link that creates a few div's in which a form is
I have a modelform that will either create a new model or edit an
I have a form that lets me create new blog posts and I'd like
I have a form_for that creates a new 'Estimate' and each of these estimates
I have form that displays several keywords (standard set of choice lists that changes
I have a form that contains a GridView control which is databound to an

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.