c# - can't cast model to ViewModel -


i have actionmethod:

public virtual actionresult search(advancedsearchviewmodel searchvm) {     var things = _things.selectall(thingtype.thing);     if (searchvm.allprovince != true)         things = things.where(pid => pid.city.provinceid == searchvm.drpprovince && pid.city.id==searchvm.city ).tolist();     if (searchvm.allgroup != true)         things = things.where(gid => gid.subgroup.maingroupid == searchvm.drpgroupid && gid.subgroup.id == searchvm.subgroup).tolist();     if (!searchvm.titleiscontains)     things = things.where(title=>title.title==searchvm.title).tolist();     else         things = things.where(title => title.title.contains( searchvm.title)).tolist();     if (searchvm.body.length > 0)         things = things.where(model=>model.description==searchvm.body).tolist();     var thinglist = things.select(x => new lastthingviewmodel { hasreward = x.isreward, id = x.id, reward = x.reward, title = x.title, requestcount = x.requests.count });      return view(mvc.index.views.viewnames.searchresult, thinglist); } 

and searchresult view :

@model ienumerable<viewmodel.thing.thinglistviewmodel> @{     viewbag.title = "searchresult";     layout = "~/views/shared/layouts/_sub.cshtml"; }  <h2>searchresult</h2> @{html.renderpartial(mvc.shared.views.viewnames._thinglist, model);} 

and thinglist partial :

@model ienumerable<viewmodel.thing.thinglistviewmodel> .... .... 

but when call search action , getting error:

the model item passed dictionary of type 'system.linq.enumerable+whereselectlistiterator`2[domainmodel.entities.thing,viewmodel.thing.lastthingviewmodel]', dictionary requires model item of type 'system.collections.generic.ienumerable`1[viewmodel.thing.thinglistviewmodel]'.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -