c# - LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression."} -
i using following code in controller
bluebusdb_context db = new bluebusdb_context(); list<selectlistitem> li =new list<selectlistitem>(); li = db.m_bluebus_states.select(s => new selectlistitem {text = s.state_name, value = convert.tostring(s.state_code)}).tolist(); viewbag.state = li; return view();
then in create view want bind dropdown , using bellow
@html.dropdownlist("state",viewbag.state list<selectlistitem>)
i getting above error..
linq entities not support convert
(see supported funuctions)
i first create anonymous type , convert selectlistitems better seperate concerns little bit:
li = db.m_bluebus_states .select(s => new { s.state_name, s.state_code }) .asenumerable() .select(x => new selectlistitem { text = x.state_name, value = x.state_code.tostring()}) .tolist();
Comments
Post a Comment