If you have supplied the lines of code that are throwing, and
Name
is a string, then genre is null.
You make sure genre is not null. The most likely solution to you problem is to skip the link creation there are a few ways to do this, but I'm not sure which'll work in Razor. this should be safe:
@foreach (var genre in Model)
{
if(genre != null)
{
@Html.ActionLink(genre.Name,"Browse",new {genre=genre.Name})
}
}
if you want to be really belt & braces and avoid any empty links
@foreach (var genre in Model)
{
if(genre != null && !string.IsNullOrWhiteSpace(genre.Name))
{
@Html.ActionLink(genre.Name,"Browse",new {genre=genre.Name})
}
}
Of course, the last example is only good if
Name
is a string.
The other thing you should check is the code that fills
Model
, the chance are there shouldn't be any nulls in there.