I would like in .ToDictionary() to concatenate both category_code and category_name in to one Value. Right now I’m only sending category_name, but I want category_name + category_code. Is it possible?
public ActionResult Create()
{
Party party = new Party();
var list = repository.GetCategories()
.Select(p => new { p.category_id, p.category_name, p.category_code })
.AsEnumerable()
.ToDictionary(m => m.category_id, m => m.category_name);
party.categories = new SelectList(list, "Key", "Value", "SelectedValue");
return View(party);
}
Why are you using
.ToDictionary(),AsEnumerable,Selectwith an anonymous object instead of something shorter:Not to mention that this kind of stuff are better adapted to your mapping layer. For example if you are using AutoMapper your controller action could look like this: