selectlist

How can I add an item to a SelectList in ASP.net MVC

﹥>﹥吖頭↗ 提交于 2019-11-26 12:08:09
问题 Basically I am looking to insert an item at the beginning of a SelectList with the default value of 0 and the Text Value of \" -- Select One --\" Something like SelectList list = new SelectList(repository.func.ToList()); ListItem li = new ListItem(value, value); list.items.add(li); Can this be done? 回答1: There really isn't a need to do this unless you insist on the value of 0. The HtmlHelper DropDownList extension allows you to set an option label that shows up as the initial value in the

How can I get this ASP.NET MVC SelectList to work?

断了今生、忘了曾经 提交于 2019-11-26 11:31:09
I create a selectList in my controller, to display in the view. I'm trying to create it on the fly, sorta thing .. like this... myViewData.PageOptionsDropDown = new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15"); It compiles, but the output is bad... <select id="PageOptionsDropDown" name="PageOptionsDropDown"> <option>10</option> <option>15</option> <option>25</option> <option>50</option> <option>100</option> <option>1000</option> </select> Notice how no item is selected? How can I fix this?? This is how I do it IList<Customer> customers = repository.GetAll<Customer>();

How can I combine two fields in a SelectList text description?

♀尐吖头ヾ 提交于 2019-11-26 07:35:48
问题 I want put in a selected list labels the name and surname of people of an EF model. I\'ve tried with this: public ActionResult Insert() { ViewData[\"accountlist\"] = new SelectList(time.Anagrafica_Dipendente.ToList(), \"ID_Dipendente\", \"Surname Name\", null); Giustificativi g = new Giustificativi(); return View(g); } but VS returns an error, because there isn\'t a attribute called \"surname name\". how can i concat the name and surname in the selectlist label? thanks 回答1: you could do