Error C# .Net "Value Cannot Be Null"

Hello I have the following error message when I testing my resgister feature. When i click on register and fillout the resgister form its giving the error message below. Please take a look at my code on google drive:https://drive.google.com/open?id=1AGoyUBRJQ6oTIMZIfJWRKx7c-RLoUej_

It is complaining about parameter name items but I do not know which parameter that is. In your code DropDownListFor has three arguments, correct? Which one is the items?

Did you click on View Details? If you need more help then click on Copy Details then paste that into a reply here.

It has id and a name.

Here are the details:

System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Parameter name: items
Source=System.Web.Mvc
StackTrace:
at System.Web.Mvc.MultiSelectList…ctor(IEnumerable items, String dataValueField, String dataTextField, String dataGroupField, IEnumerable selectedValues, IEnumerable disabledValues, IEnumerable disabledGroups)
at System.Web.Mvc.SelectList…ctor(IEnumerable items, String dataValueField, String dataTextField)
at ASP._Page_Views_Account_Register_cshtml.Execute() in C:\Users\kayhareni\Documents\New\Rentals - Copy\Rentals\Views\Account\Register.cshtml:line 66
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.StartPage.RunPage()
at System.Web.WebPages.StartPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)

Well at a guess, since there’s very few things in that list that could be null without throwing a quicker error than that… what does your immediate window tell you the value of Model.MembershipTypes is?

This is membershipType Model:

namespace Rentals.Models
{
    public class MembershipType
    {
        [Required]
        public int    Id { get; set; }

        [Required]
        public string Name { get; set; }

        [Required]
        [DataType(DataType.Currency)]
        public byte   SignUpFee { get; set; }

        [DisplayName("Rental Rate")]
        [Required]
        public byte   ChargeRateOneMonth { get; set; }

        [Required]
        public byte   ChargeRateSixMonth { get; set; }
    }
}

So its getting data as a drop down list by using the id and name only. Ive attached my source code as a google drive link

I cannot look at the source code, Google does not know how to show most of the relevant file types. I cannot download the solution or portions of it, Google hangs trying to create a zip file. Google drive is no good for this, the Google Drive does not help.

Unfortunately I am unfamiliar with MVC.

I assume you are modifying something that someone else developed.

Note that m_hutley asked for the value of Model.MembershipTypes, not the definition of MembershipType.

One problem is that programmers like to put multiple things into a single statement. The problem is that when there is a problem we have difficulty knowing the cause of the problem. Here is something I often do to diagnose things like this. Break the line up into multiple statements. For example if we had:

@Html.DropDownList("Country", ViewData["Countries"] as SelectList, new { @class = "form-control" })

Then you can make that:

@{ string name = "Country";}
@{ SelectList selectList = ViewData["Countries"] as SelectList;}
@Html.DropDownList(name, selectList, new { @class = "form-control" })

Then when you debug you can look at the value of name and selectList.

I am now learning this, is there anyone that can help with this since @samuel is not familiar with this?

It doesn’t look like m.MembershipTypeID is valid (or it’s coming up null)

How can i fix this Dave?

Oh, sorry. I think it’s actually…

new SelectList(Model.MembershipTypes, "id", "name")

It should be

new SelectList(Model.MembershipTypes)

I tried this but it did not work, getting the same error message.

You have not done much to help us help you. In most forums they ask for simple samples, complete large projects (as in your Google Drive) are less helpful. However that project in Google Drive is not accessible to us.

Did you try my suggestion? You could have solved the problem by now if you tried.

Samuel, what is best way to make my file acessible? I tried to add it to github but since the file is 100mb its not letting me upload it

Perhaps it would be possible to post just the relevant page here. Perhaps you can create a version of the page that is smaller that recreates the problem.

As for using Google Drive, when I try to download the project Google Drive tries to zip the files and then hangs. Perhaps if you were to do the zipping then we could download that.

I do not know what page in what folder that code is in; I think you have not told us that. Tell us what page in what folder the code is in.

You certainly should be able to upload to GitHub but I know that GitHub can be frustrating.

Im Sorry, I am now learning this and will definitely follow those instruction moving on:
here is the zip foldder link:https://drive.google.com/open?id=1kTzU3AkAw4z-mMkIOh8WLrNxMhmKkrxO

The error is coming from the views folder → account → register.cshtml

I don’t see a zip file at that location.

I don’t see a DropDownList in the register.cshtml page.

Samuel, did u try to run the application? It will take you to the error.

I can’t run the application. I can’t download it.

I think other forums would prefer that you don’t expect people trying to help you to download an entire large application. If you were to ask this in StackOverflow then they would request a sample that was more relevant to just the problem but they would also require you to search for previous answers and not post a duplicate. I am just saying that it helps to help us help you.

I understand.

Can you please download it here now:
http://www.filedropper.com/rentals-copy