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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:46:16+00:00 2026-05-22T17:46:16+00:00

Im trying to get my head around the entity framework 4.1 codefirst approach for

  • 0

Im trying to get my head around the entity framework 4.1 codefirst approach for MVC3.

I am trying to add a dropdownlist into a create view with little luck.

I have a model looking like

public class BusinessModel
{
    public int Id { get; set; }

    [Required]
    public string BusinessName { get; set; }
    [Required]
    public string PhoneNumber { get; set; }


    public int BusinessTypeId { get; set; }
    public virtual BusinessTypeModel BuinessTypeModel { get; set; }

}

public class BusinessTypeModel
{
    public int Id { get; set; }
    public string BusinessType { get; set; }
}

My dropdown list looks like

     @Html.DropDownListFor(model => model.BusinessTypeId,
         ((IEnumerable<CRM.Models.BusinessTypeModel>)ViewBag.BuinessTypes)
    .Select(option => new SelectListItem
    {

        Text = (option == null ? "None" : option.BusinessType),

        Value = option.Id.ToString(),

        Selected = (Model != null) && (option.Id == Model.BusinessTypeId)

    }), "Select Business Type...")

I havent done anything yet with my controller so its vanilla

 public ActionResult Create()
    {
        return View();
    } 

However I get a null error

Value cannot be null.
Parameter name: source

Now I assume this is null because I am not binding the dropdown list correctly however I am not sure where I am going wrong.

Could someone please help with what im doing wrong?

  • 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-22T17:46:17+00:00Added an answer on May 22, 2026 at 5:46 pm

    you use “ViewBag.BuinessTypes” in your View,

    Maybe you should assign a valeu of ViewBag.BuinessTypes in Create Controller?

    like:

     public ActionResult Create()
        {
            ViewBag.BuinessTypes = ...;        
            return View();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to wrap my head around the Entity Framework and am having trouble
I've just started foraying into EF, and I'm trying to get my head around
Just trying to get my head around Generics by reading this enlightening article by
I was trying to get my head around XAML and thought that I would
I'm trying to get my head around why the following doesn't work. I have
I'm trying to get my head around the Error Handling in MVC. What I'm
I'm trying to get my head around mutable vs immutable objects. Using mutable objects
I am trying to get my head around a LINQ issue. The ultimate goal
I'm trying to get my head around tuples (thanks @litb), and the common suggestion
I'm trying to get my head around Domain Driven Design and the examples I've

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.