These are my Song and 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 this is inside my 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( What should i type here );
}
else {
return View(songset.ToList());
}
}
This is how my app looks like: https://i.stack.imgur.com/fJb70.jpg
Question is - What should I put in retun View inside controller to 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 it says(p in second .Any underlined red) Lambda expression with a statement body cannot be converted to an expression tree