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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:31:05+00:00 2026-06-13T20:31:05+00:00

I have a create view for invoices that is failing on db.SaveChanges() on the

  • 0

I have a create view for invoices that is failing on db.SaveChanges() on the HTTPPOST. The exception message is {“Invalid column name ‘UserDetail_UserId’.”}. In the POST controller it looks like the invoiceitem object I’m trying to add to my InvoiceItems table is populated correctly with the selected username from a dropdownlistfor that gets populated by usernames from my UserDetails table. “UserId” is the key column in the UserDetails table, but it’s not used in the dropdownlist so I’m unclear why any data is trying to be saved to a “UserDetail_UserId” column. My code below:

Models:

public class InvoiceItem
{
    //Identity Column
    public int ServiceID { get; set; }

    [Key]
    public string ProfileUserName { get; set; }

    public DateTime InvoiceDate { get; set; }
    public string Address { get; set; }
    public string Note { get; set; }
    public decimal Price { get; set; }
    public decimal SubTotal { get; set; }
    public bool InvoicePaid { get; set; }
}

public class UserDetail
{
    [Key]
    public Guid UserId { get; set; }
    public string ProfileUserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string FullName { get; set; }
    public string Address { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }
    public string Phone { get; set; }
    public DateTime DateUpdated { get; set; }
    public virtual ICollection<InvoiceItem> InvoiceItems { get; set; }
}

public class ProShotDB : DbContext
{
    public DbSet<UserDetail> UserDetails { get; set; }
    public DbSet<UserLinkToken> UserLinkTokens { get; set; }
    public DbSet<InvoiceItem> InvoiceItems { get; set; }
}

Controllers:

public ActionResult Create()
    {
        ViewBag.ProfileUserNames = db.UserDetails.Select(
        c => new
        {
            ProfileUserName = c.ProfileUserName,
            NameAddress = c.FullName + " - " + c.Address
        });
        return View();
    }

    [HttpPost]
    public ActionResult Create(InvoiceItem invoiceitem)
    {
        decimal Tax = 1.066m;
        if (ModelState.IsValid)
        {
            invoiceitem.InvoiceDate = DateTime.Now;
            invoiceitem.SubTotal = invoiceitem.Price*Tax;
            invoiceitem.InvoicePaid = false;

            db.InvoiceItems.Add(invoiceitem);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        ViewBag.ProfileUserNames = db.UserDetails.Select(
        c => new
        {
            ProfileUserName = c.ProfileUserName,
            NameAddress = c.FullName + " - " + c.Address
        });
        return View(invoiceitem);
    }

View:

@model Pro_Shot_Portal.Models.InvoiceItem

@{
    ViewBag.Title = "Input Invoice";
}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>Input Invoice:</legend>

    <div class="alert alert-error" style="width:250px;">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>Warning!</strong> Assigning invoice to wrong user could cause major problems, please triple check before proceeding.
    </div>
    <div class="editor-label">
        @Html.LabelFor(model => model.ProfileUserName, "Attach invoice to user")
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model => model.ProfileUserName, new SelectList(ViewBag.ProfileUserNames, "ProfileUserName", "NameAddress"), "-- Pick Client For Invoice --")
        @Html.ValidationMessageFor(model => model.ProfileUserName)
    </div>

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

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

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

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

<div>
    @Html.ActionLink("Cancel Invoice Creation", "Index")
</div>

From what I can tell the invoiceitem model object properties are filled with the proper data, and the only database change I’m invoking with db.SaveChanges() is “db.InvoiceItems.Add(invoiceitem);”. Can anyone tell me where and why it’s trying to access, write or update a column named “UserDetails_UserId”. Maybe I messed something up on the DropdownListFor since that’s the only part interacting with the UserDetails table?

Thanks.

  • 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-13T20:31:06+00:00Added an answer on June 13, 2026 at 8:31 pm

    You have a one-to-many relationship setup, the column name you are seeing with the underscores in the exception is the relationship default generated. See here for more details.

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

Sidebar

Related Questions

I have three models that are coming together to create one view model and
If i have a controller action Create that returns a view with the following
I have to create a View that shows a field created by concatenating some
I need to create a view with a column that indicates which table does
I have a Create View page in my MVC3 project to create instances of
I have created a view for a table as: CREATE VIEW anonymous_table AS SELECT
I have a problem with the Create View in the SimpleRepository example in Subsonic
How can I create View on Linked Server db. For Example I have a
I create a indexed view View1 on Table1 and Table2 and have instead of
Possible Duplicate: Create an alert on any view controller after Facebook request:didFailWithError: I have

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.