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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:45:12+00:00 2026-05-31T08:45:12+00:00

I have a registration view in my web app. However, account registration would be

  • 0

I have a registration view in my web app. However, account registration would be unsuccessful and my drop-down menu would be outlined in red.

Here is my drop down code:

<div class="editor-label">  
   @Html.LabelFor(model => model.CompanyId, "Company")  
</div>   
<div class="editor-field">  
   @Html.DropDownList("Companies", "<Select Company>")  
</div>

Here is my associated code in the view model:

[Display(Name = "Company")]    
public int? CompanyId { get; set; }

public IEnumerable<SelectListItem> Companies { get; set; }

Here is my associated code in the controller before I return the view:

ViewBag.Companies = new SelectList(db.Companies, "CompanyId", "CompanyName");

As I debug, I find that ModelState.IsValid returns false, and therefore re-returns the view (and re-sets ViewBag.Companies in my case).

How do I complete a successful registration? I do fill out each required field within parameters. It is not required to select company. When I do not select a company, ModelState.IsValid returns true and runs through the code. However, I would like the user to have the option to associate with his company.

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-05-31T08:45:13+00:00Added an answer on May 31, 2026 at 8:45 am

    Why would you need setting ViewBag.Companies, when you’ve got the better approach – having select list into the model? No need to use ugly ViewBag

    You should have something like this

    ViewModel

    public class RegisterViewModel
    {
         [Display(Name = "Company")]    
         public int? CompanyId { get; set; }
    
         public IEnumerable<SelectListItem> Companies { get; set; }
    }
    

    Controller

    [HttpGet]
    public ActionResult Register()
    {
         RegisterViewModel viewModel = new RegisterViewModel();
         viewModel.Companies = new SelectList(db.Companies, "CompanyId", "CompanyName");
    
         return View(viewModel);
    }
    

    And in the view

    <div class="editor-label">  
       @Html.LabelFor(model => model.CompanyId, "Company")  
    </div>   
    <div class="editor-field">  
       @Html.DropDownListFor(model => model.CompanyId, Model.Companies, "<Select Company>")  
    </div>
    

    This will bind your CompanyId on server correctly.

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

Sidebar

Related Questions

I have such view that handles user registration. After creating new user i want
In my web application i have registration form, when user register i want to
I'm using javascript and jQuery. I have a problem that my web app has
I have the following View code: @using (Html.BeginForm(Login, Press, FormMethod.Post)) { <fieldset> <legend>User Registration</legend>
In my iPhone app, I have a registration form. The registration form contains many
I have a registration form in the side bar of my web application. When
I have a registration page and would like to perform some validation (in addition
I want to have a registration page and a create account page. After filling
I have a team registration app. A user signs up to be a part
I have a third party app that requires a template. I would like to

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.