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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:23:15+00:00 2026-05-31T20:23:15+00:00

I have a viewmodel. public class RegistrationViewModel { public RegisterModel Register { get; set;

  • 0

I have a viewmodel.

    public class RegistrationViewModel
{
    public RegisterModel Register { get; set; }
    public Producer Producer { get; set; }

    public IEnumerable<UserType> UserTypes { get; set; }
    public IEnumerable<Producer> Producers { get; set; }

}

In the view, the user puts in their registration credentials and then selects a producer that they are a part of. They can also create a new producer on the page as well. However, when they do this my ModelState is invalid because the Producer doesn’t have an ID field. This is a new Producer record and I shouldn’t need to assign an ID before it is created in my database, right? ID is my identity field in SQL. I noticed that my scaffolded code for other domain models passes back an ID of 0 without any issues. Am I doing this correctly at all? Is this related to the viewmodel? Any help would be greatly appreciated.

Producer class:

    public class Producer
{
    public int ProducerID { get; set; }

    public string Name { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Postal { get; set; }
    public string Country { get; set; }

    [DataType(DataType.PhoneNumber)]
    public string Phone { get; set; }

    [DataType(DataType.EmailAddress)]
    public string Email { get; set; }

    public string Website { get; set; }

    public string CreatedBy { get; set; }
    public DateTime CreatedOn { get; set; }
    public string UpdatedBy { get; set; }
    public DateTime? UpdatedOn { get; set; }
    public Boolean Active { get; set; }


    public virtual ICollection<Wine> Wines { 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-05-31T20:23:16+00:00Added an answer on May 31, 2026 at 8:23 pm

    I prefer to have a view model that is specific to the create action that doesn’t have this key, although for reuse some do.

    In that case, as you mentioned zero should be just fine. Ensure the key is written to the page though, check for a hidden field that has zero in it.

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

Sidebar

Related Questions

I have something like this public class ViewModel { public List<Books> Test {get; set;}
Suppose you have a viewModel: public class CreatePersonViewModel { [Required] public bool HasDeliveryAddress {get;set;}
I have a ViewModel as such: public class EmployeeViewModel { Employees employee{ get; set;
I have the following ViewModel public class NewCustomerViewModel { public long CustomerId {get;set;} public
I have a view model public class ViewModel { public string Text { get;
I have a ViewModel: public class Page { public int Id { get; set;
I have following ViewModel: public IEnumerable<SelectListItem> SelectAdminsInGroup { get; set; } public IEnumerable<SelectListItem> SelectAdminsNotInGroup
So i have something along the lines of private ObservableCollection<ViewModel> _internal; public ObservableCollection<ViewModel> BoundInternal{get;set};
Suppose I have ViewModel like public class AnotherViewModel { public string Name { get;
This is my Viewmodel public class IndexViewModel { public string QuestionText { get; set;

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.