Hmm, your strange thing: you pass Dictionary<string, string>
to your select list and claim that the Field value is "ProductId" and the TextField is "ProductName".
There are no such properties in your dictionary ... Good text customization.
So you need the Product class (or something else)
public class Product { public int ProductId {get;set;} public string ProductName {get;set;} }
and use it even for testing purposes
public ActionResult _AjaxLoading(string text) { var products= new List<Product> { new Product{ProductId = 1, ProductName="b"} }; return new JsonResult { Data = new { Text = "Abc", Value = "123", Products= new SelectList(products, "ProductID", "ProductName") } }; }
EDIT:
By the way, if you want โAbcโ and โ123โ in SelectList, this is the wrong way to do it, look at @Gaby's answer in your previous post to fooobar.com/questions/1411336 / ...
EDIT 2:
try again
so firt, some of my usual extension classes (I limited them, they were more universal, but ... anyway)
public static class ComboExtensions { public static IEnumerable<SelectListItem> ToSelectListItem<T>(this IEnumerable<T> enumerable, Func<T, string> text, Func<T, int> value) { return enumerable.Select(item => new SelectListItem { Text = text(item).ToString(), Value = value(item).ToString(), }).AsEnumerable(); } public static IEnumerable<SelectListItem> WithDefaultValue(this IEnumerable<SelectListItem> selectListItems, int defaultValue = 0, string chooseText = "choose") { IList<SelectListItem> items = selectListItems.ToList(); items.Insert(0, new SelectListItem {Value = defaultValue.ToString(), Text = chooseText});
then
public ActionResult _AjaxLoading(string text) { var products = new List<Product> { new Product {ProductId = 1, ProductName = "b"} }.ToSelectListItem(m => m.ProductName, m => m.ProductId) .WithDefaultValue(1, "abc"); return new JsonResult { Data = products } }; }