I have created a table on my users page which shows all the restaurants they are following. But when I run the page I receive the error Object reference not set to an instance of an object.
For the line
@foreach (var RestaurantSearch in Model.RestaurantSearch)
Is there a different way that this code should be written?
Profile Page code
@foreach (var RestaurantSearch in Model.RestaurantSearch)
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentUser = manager.FindById(User.Identity.GetUserId());
if (RestaurantSearch.User1ID == @currentUser.Id)
{
<tr>
<td>
@Html.DisplayFor(modelItem => RestaurantSearch.RestaurantID)
</td>
<td>
@Html.DisplayFor(modelItem => RestaurantSearch.User1ID)
</td>
<td>
@Html.ActionLink("Details", "Details", "Restaurant", new { id = RestaurantSearch.RestaurantID }, null) |
</td>
</tr>
}
}
</table>
Followviewmodel
public class Followviewmodel
{
public IEnumerable<BiteWebsite.Models.Followuser> UserSearch { get; set; }
public IEnumerable<BiteWebsite.Models.FollowRestaurant> RestaurantSearch { get; set; }
public string Name { get; set; }
public string Cuisine { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string UserName { get; set; }
}