c# - I am trying to implement search functionality but I am stuck -
these song , playlist models:
namespace konacno.models { using system; using system.collections.generic; public partial class song { public int id { get; set; } public string name { get; set; } public string singer { get; set; } public string year { get; set; } public int playlistid { get; set; } public virtual playlist playlist { get; set; } } }
namespace konacno.models { using system; using system.collections.generic; public partial class playlist { public playlist() { this.song = new hashset<song>(); } public int id { get; set; } public string playlistname { get; set; } public virtual icollection<song> song { get; set; } } }
and inside songcontroller:
public actionresult index(string searchby, string search) { var songset = db.songset.include(s => s.playlist); if (searchby == "name") { return view(songset.where(x => x.name.contains(search)).tolist()); } else if (searchby == "singer") { return view(songset.where(x => x.singer.contains(search)).tolist()); } else if (searchby == "year") { return view(songset.where(x => x.year.contains(search)).tolist()); } else if (searchby == "playlist") { return view( should type here ); } else { return view(songset.tolist()); } }
this how app looks like: https://imgur.com/1l9bvoe
question - should put in retun view inside controller check if selected songset contains wanted playlist?
i have tried this:
else if (searchby == "playlist") { return view( songset.any(x => x.gettype().getproperties().any(p => { var value = p.getvalue(x); return value != null && value.tostring().contains(search); } ) ) ); }
but says(p in second .any underlined red) lambda expression statement body cannot converted expression tree
just use playlist
navigation property:
return view(songset.where(x => x.playlist.playlistname.contains(search)).tolist());
Comments
Post a Comment