ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Migration to v5
Title:
B
I
{code}
?
How can migrate this dropdown ? public ActionResult GetItems(string v) { var list = new List<SelectableItem> {}; list.Add(new SelectableItem { Text = "Male", Value = "M", Selected = v == "M" }); list.Add(new SelectableItem { Text = "Female", Value = "F", Selected = v == "F" }); return Json(list); }
Save Changes
Cancel
Meccanica Rossi
asked at 12 Jul 2017
Answers
B
I
{code}
?
public ActionResult GetItems() { var list = new List<KeyContent> {}; list.Add(new KeyContent ("M", "Male")); list.Add(new KeyContent ("F", "Female")); return Json(list); } and in the view just set the value: usually it's done by setting the viewmodel property in the controller `input.Gender = "M"; return View(input);` or in the view `Html.Awe().Helper().Value("M")`
Save Changes
Cancel
Omu
answered at 12 Jul 2017
public virtual ActionResult GetItems(IEnumerable<int> v, int calendarid) { v = v ?? new List<int>(); var list = new List<KeyContent> { }; list.AddRange(db.Calendars.Where(c => c.IsDeleted == false && c.Id == calendarid).SingleOrDefault().CourseCards.ToArray().Select(o => new KeyContent { Content = o.Student.Name, Key = o.Student.Id.ToString(), Selected = v.Contains(o.Student.Id) })); var distinctPartecipants = list.GroupBy(s => s.V).Select(s => s.First()); return Json(distinctPartecipants.ToList()); }
at 25 Jul 2017
Meccanica Rossi
This is about a CheckBoxList is more complex .. how convert it ? PS: error occour in "Selected = v.Contains(o.Student.Id)" and "list.GroupBy(s => s.V)"
at 25 Jul 2017
Meccanica Rossi
the requirement is to return a collection of KeyContent and in the view to set the value of the helper, the rest is up to you from seeing your code I would recommend to always transform to KeyContent in the last step ( `.Select( o => new KeyContent..` ) and call `.ToList()` before transforming to `KeyContent`
at 25 Jul 2017
Omu
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK