asp.net mvc - Getting wrong order with DropDownListFor -
i have following table:
create table categories ( id number(1,0) primary key, category varchar2(20) ); insert categories values(1,"general"); insert categories values(2,"interior"); insert categories values(3,"exterior"); insert categories values(4,"tuning"); insert categories values(5,"body");
and have enum matches above table:(please don't ask why)
public enum category {general=1,interior,exterior,tuning,body}
here's view model:
public class ordersviewmodel{ public ienumerable<seleclistitem> categories{get;set;} public order order{get;set;} } public order{ public category category{get;set;} }
i use memory cache avoid traveling database, i've got following method gets object cache if exists, otherwise fetches database:
public t getitemfromcache<t>(string key, func<t> getfromdb) t : class { t item = memorycache.default.get(key) t; if (item == null) { item = getfromdb(); if (item != null) memorycache.default.add(key, item, datetime.now.addminutes(1)); } return item; }
in action method following:
public actionresult index(){ myviewmodel vm=new myviewmodel(); vm.categories = getitemfromcache("categories", () => context.categories.orderby(x => x.id).tolist().select(x => new selectlistitem { value = x.id.tostring(), text = x.category })); }
and in view this:
@html.dropdownlistfor(x => x.order.category, model.categories, "",)
in action method, can see, use entity framework fetching records database , order items id. have ordered. problem is, periodically, position of last 2 items in result list swapped, instead of being:
general,interior,exterior,tuning,body
i get
general,interior,exterior,body,tuning
and fix restarting iis. recycling pool job. don't use javascript populating dropdownlist. have idea problem might be?
Comments
Post a Comment