Skip to content

Dropdownlist

albert albert

Asked Jul 20, 2014, 10:54 PM EDT2 answers
Share
LinkedInX
Hi everybody,
 
I have this:
 controller
[code]
 
C#
//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]
 
C#
 public class FaqOverviewModel
    {
        public int Id { get; set; }
        public string EmailBericht { get; set; }
        public string Naam { get; set; }

        public FaqOverviewModel()
        {

            Categorie = new List();
        }

        public FaqOverviewModel(IEnumerable categories)
        {
            this.Categorie = categories;


        }


        #region FAQCategorie
        private readonly IEnumerable Categorie;



        public int? SelectedCategoriedFaqId { get; set; }
        public IEnumerable FAQCategorieItems
        {

            get
            {
                return new SelectList(Categorie, "Id", "Naam");
            }

        }
[/code] 
 
View:
 
[code]
 
@using Multitask.Regenboog.Medicijnverstrekking.Domain
@model Multitask.Regenboog.Medicijnverstrekking.WebApplication.ViewModels.FAQ.FaqOverviewModel
Code
@{
    ViewBag.Title = "Index";
}

Support

@using (Html.BeginForm())
{

@Html.LabelFor(model => model.SelectedCategoriedFaqId, "Categorie:")
@Html.DropDownListFor(x => x.SelectedCategoriedFaqId, Model.FAQCategorieItems)
@*
@Html.LabelFor(m => m)
*@
@*
@Html.LabelFor(model => model.SelectedSubCategorieFaqId, "Onderwerp:")
@Html.DropDownListFor(m => m.SelectedSubCategorieFaqId, Model.FaqSubCategorieItems, new { style = "width: 150px" })
*@

Code
        @Html.LabelFor(model => model.EmailBericht, "Bericht:")
        @Html.TextAreaFor(x => x.EmailBericht)



}
[/code] 
 
I see the dropdownlist, but now items in it.
 
Thank you 

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    can you please point out specific area where code is not working as desired, it's hard to go through all lines

    twitter @sumitjolly
    0