我在ASP.NET應用程序中的搜索方法中收到Visual Studio 2010中的「無法訪問的代碼」消息。 這是方法:在ASP.NET應用程序中檢測到無法訪問的代碼
public ActionResult SearchIndex(string artist, string albumGenre, string searchString)
{
var GenreList = new List<string>();
var GenreQuery = from d in storeDB.Albums orderby d.Genre.Name select d.Genre.Name;
GenreList.AddRange(GenreQuery.Distinct());
ViewBag.albumGenre = new SelectList(GenreList);
var ArtistList = new List<string>();
var ArtistQuery = from a in storeDB.Artists orderby a.Name select a.Name;
ArtistList.AddRange(ArtistQuery.Distinct());
ViewBag.artist = new SelectList(ArtistList);
var albums = from m in storeDB.Albums select m;
if (string.IsNullOrEmpty(artist))
{
return View(albums);
}
else
{
return View(albums.Where(f => f.Artist.Name == artist));
}
if (!String.IsNullOrEmpty(searchString))
{
return View(albums.Where(s => s.Title.Contains(searchString)));
}
if (string.IsNullOrEmpty(albumGenre))
{
return View(albums);
}
else
{
return View(albums.Where(x => x.Genre.Name == albumGenre));
}
}
對於這一說法I'getting消息:
if (!String.IsNullOrEmpty(searchString))
{
return View(albums.Where(s => s.Title.Contains(searchString)));
}
我要去哪裏錯了嗎?
非常感謝。問題已經解決了 ;)。 –