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

  • Home
  • SEARCH
  • 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 5992881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:35:44+00:00 2026-05-22T23:35:44+00:00

I followed the instruction in this post , but when I try to add

  • 0

I followed the instruction in this post, but when I try to add a product I get this error:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Value cannot be null.
Parameter name: source 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: source

Source Error: 


Line 63: </div>
Line 64: <div class="editor-field">
Line 65:     @Html.DropDownListFor(model => model.CategoryId, ((IEnumerable<GAM.Models.Category>)ViewBag.PossibleCategories).Select(option => new SelectListItem {
Line 66:         Text = (option == null ? "None" : option.Name), 
Line 67:         Value = option.Id.ToString(),

The controller code is:

public ActionResult Create()
{
    ViewBag.PossibleCategory = context.Categories;
    return View();
} 

//
// POST: /Product/Create

[HttpPost]
public ActionResult Create(Product product)
{
    if (ModelState.IsValid)
    {
        context.Products.Add(product);
        context.SaveChanges();
        return RedirectToAction("Index");  
    }

    ViewBag.PossibleCategory = context.Categories;
    return View(product);
}

And the code of the view is:

 @Html.DropDownListFor(model => model.CategoryId, ((IEnumerable<GAM.Models.Category>)ViewBag.PossibleCategories).Select(option => new SelectListItem {
    Text = (option == null ? "None" : option.Name), 
    Value = option.Id.ToString(),
    Selected = (Model != null) && (option.Id == Model.CategoryId)
}), "Choose...")
@Html.ValidationMessageFor(model => model.CategoryId)
  • 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-22T23:35:45+00:00Added an answer on May 22, 2026 at 11:35 pm

    Your problem is the following:

    You assign this property within the Controller:

    ViewBag.PossibleCategory = context.Categories;
    

    Then, in your View you try to read this dynamic ViewBag property:

    ViewBag.PossibleCategories
    

    Can you see the error? You’re giving different names… You do not get compile time checking because ViewBag uses the new C# 4 dynamic type. ViewBag.PossibleCategories will only be resolved at runtime. As there’s no ViewBag property that matches ViewBag.PossibleCategories you get this error: Value cannot be null. Parameter name: source

    To solve this just do this:

    ViewBag.PossibleCategories = context.Categories;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed the instruction in this blog to add ScrollIntoView to ItemsControl . But
I followed this instruction but not worked for me. I just wanna install and
I know there are a lot of posts about this, but I cannot get
I followed the instruction on this page ( http://developers.facebook.com/docs/authentication/ ) to add facebook authentication
I followed the instructions on this post: Asp.net mvc3 razor with multiple submit buttons
I followed the instruction of this article and setup an Redmine site on my
This is starting to drive me insane, as I've followed every instruction I can
I've been trying to follow this blog post to get my python version back
I have followed this instruction in setting my webkit repository locally: http://trac.webkit.org/wiki/UsingGitWithWebKit And then
I have followed the Accepted Answer's instructions from this post as regards creating a

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.