albert albert

albert albert

  • NA
  • 524
  • 0

dropdownlist

Jul 21 2014 2:54 AM
Hi everybody,
 
I have this:
 controller
[code]
 
//FaqService faqService;
FaqCategorieService faqCategorieService;
public FAQController(FaqCategorieService faqCategorieService)
{
this.faqCategorieService = faqCategorieService;
}
// GET: FAQ
[HttpGet]
public ActionResult Index(FaqOverviewModel model)
{
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..." });
//var cats = faqCategorieService.GetAll().ToList();
return View(model);
// return RedirectToAction("Index");
}
[/code] 
 
 modelview
[code]
 
public class FaqOverviewModel
{
public int Id { get; set; }
public string EmailBericht { get; set; }
public string Naam { get; set; }
public FaqOverviewModel()
{
Categorie = new List<FaqCategorie>();
}
public FaqOverviewModel(IEnumerable<FaqCategorie> categories)
{
this.Categorie = categories;
}
#region FAQCategorie
private readonly IEnumerable<FaqCategorie> Categorie;
public int? SelectedCategoriedFaqId { get; set; }
public IEnumerable<SelectListItem> FAQCategorieItems
{
get
{
return new SelectList(Categorie, "Id", "Naam");
}
}
[/code] 
 
View:
 
[code]
 
@using Multitask.Regenboog.Medicijnverstrekking.Domain
@model Multitask.Regenboog.Medicijnverstrekking.WebApplication.ViewModels.FAQ.FaqOverviewModel
@{
ViewBag.Title = "Index";
}
<h2>Support</h2>
@using (Html.BeginForm())
{
<p>
<span class="fixedLabelWidth">@Html.LabelFor(model => model.SelectedCategoriedFaqId, "Categorie:")</span>
@Html.DropDownListFor(x => x.SelectedCategoriedFaqId, Model.FAQCategorieItems)
</p>
@*<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>*@
<p>
<span class="fixedLabelWidth">@Html.LabelFor(model => model.EmailBericht, "Bericht:")</span>
@Html.TextAreaFor(x => x.EmailBericht)
</p>
}
[/code] 
 
I see the dropdownlist, but now items in it.
 
Thank you 
  

Answers (2)