0
Answer

Dropdownlist

albert albert

albert albert

10y
573
1
Hi everybody,
 
I have this:
 
[code]
 
using Multitask.Regenboog.Medicijnverstrekking.Domain;
using Multitask.Regenboog.Medicijnverstrekking.WebApplication.Validation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Multitask.Regenboog.Medicijnverstrekking.WebApplication.ViewModels.FAQ
{
public class FaqOverviewModel
{
public int Id { get; set; }
public string EmailBericht { get; set; }
public string Naam { get; set; }
public FaqOverviewModel(List<FaqCategorie>Categorie)
{
this.Categorie = Categorie;
}
public FaqOverviewModel()
{
// TODO: Complete member initialization
}
#region FAQCategorie
private readonly List<FaqCategorie> Categorie;
public int? SelectedCategoriedFaqId { get; set; }
public IEnumerable<SelectListItem> FAQCategorieItems
{
get
{
return new SelectList(Categorie, "Id", "Name");
}
}
#endregion
#region subcategorie
#endregion
}
}
[/code] 
 
 
[code]
 
public class FAQController : Controller
{
//FaqService faqService;
FaqCategorieService faqCategorieService;
public FAQController(FaqCategorieService faqCategorieService)
{
this.faqCategorieService = faqCategorieService;
}
// GET: FAQ
[HttpGet]
public ActionResult Index()
{
//var cats = faqCategorieService.GetAll().ToList();
var categories = faqCategorieService.GetAll().OrderBy(x => x.Naam)
.Select(a => new FaqOverviewModel()
{
Id = a.Id,
Naam = a.Naam
}).ToList();
foreach (var categorie in categories)
{
categorie.Naam = categorie.Naam + " (" + categorie.Id.ToString() + ")";
}
categories.Insert(0, new FaqOverviewModel() { Id = -1, Naam = "Maak een keuze..." });
return View(new FaqOverviewModel());
}
[/code] 
 
[code]
 
@using Multitask.Regenboog.Medicijnverstrekking.Domain
@model Multitask.Regenboog.Medicijnverstrekking.WebApplication.ViewModels.FAQ.FaqOverviewModel
@{
ViewBag.Title = "Index";
}
<h2>Support</h2>
@using (Html.BeginForm())
{
//if (Model.ZorgverzekeraarInvoerEnabled)
//{
<span class="fixedLabelWidth">@Html.LabelFor(model => model.SelectedCategoriedFaqId, "Categorie:")</span>
@Html.DropDownListFor(x => x.SelectedCategoriedFaqId, Model.FAQCategorieItems )
//@Html.HiddenFor(model => model.ZorgverzekeraarInvoerEnabled)
@*<div class="editor-label">
@Html.LabelFor(m => m)
</div>*@
@*<div class="editor-field">
<span class="fixedLabelWidth">@Html.LabelFor(model => model.SelectedSubCategorieFaqId, "Onderwerp:")</span>
@Html.DropDownListFor(m => m.SelectedSubCategorieFaqId, Model.FaqSubCategorieItems, new { style = "width: 150px" })
</div>*@
<span class="fixedLabelWidth">@Html.LabelFor(model => model.EmailBericht, "Bericht:")</span>
@Html.TextAreaFor(x => x.EmailBericht)
@*}*@
}
[/code] 
 
But I get this error:

Value cannot be null.
Parameter name: items

 
By this line:
 
get
{
return new SelectList(Categorie, "Id", "Name");
}
 
 
Thank you