Hi All,
I'm having issues with the same project i posted earlier, although i'm further along. To provide a bit of background, i'm dealing accounting data from a flat file that i'm making hierachical via the use of cascasding dropdownlists. The top level object, 'Entity' is working fine, the second level object that gets populated as a result of what is selected in 'Entity', is called 'Account Type'.
When i select an Entity from the Entity dropdown triggering a post back, from debugging it looks like everything is loaded correctly. I grab the EntityCode that i then pass through to a LINQ query to get all the AccountTypes for that EntityCode. The AccountTypes SelectList is loaded correctly with values. I break just when the AccountTypes are about to be bine (line 38 of the view) and the object is correctly loaded, yet the null reference exception below is thrown:
<div class="titleerror">NullReferenceException: Object reference not set to an instance of an object.</div>Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList.GetListItemsWithValueField()
NullReferenceException: Object reference not set to an instance of an object.
Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList.GetListItemsWithValueField()
Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList.GetListItems()
Microsoft.AspNetCore.Mvc.Rendering.MultiSelectList.GetEnumerator()
System.Collections.Generic.List.AddEnumerable(IEnumerable<T> enumerable)
System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.GenerateGroupsAndOptions(string optionLabel, IEnumerable<SelectListItem> selectList, ICollection<string> currentValues)
Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.GenerateSelect(ViewContext viewContext, ModelExplorer modelExplorer, string optionLabel, string expression, IEnumerable<SelectListItem> selectList, ICollection<string> currentValues, bool allowMultiple,
object htmlAttributes)
Microsoft.AspNetCore.Mvc.TagHelpers.SelectTagHelper.Process(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner+<RunAsync>d__0.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
SharedData.Pages.AccountCoding.Index_Page+<<ExecuteAsync>b__18_4>d.MoveNext() in Index.cshtml
<select asp-for="@Model.accountCodingView.SelectedAccountTypeCode" asp-items="@Model.accountCodingView.AccountTypes" class="form-control" onchange="this.form.submit();">
The link to the fiddle is here:
https://dotnetfiddle.net/VjABOj
The razor page is represented as the "View" and "Controller" and the AccountCodingView viewmodel is in the model section. Of course it doesn't run on here, but it all runs fine on my dev machine. From what i can tell, everything is loaded correctly and should be working judging from my debugging. I must be missing something obvious!
Cheers,
Sam