1
我在我的用戶頁面上創建了一張表,其中顯示了他們所關注的所有餐館。但是,當我運行的頁面我收到錯誤Object reference not set to an instance of an object.
對於線未將對象引用設置爲對象asp.net的實例c#
@foreach (var RestaurantSearch in Model.RestaurantSearch)
是否有不同的方式,這個代碼應該寫的?
個人主頁代碼
@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; }
}
我敢打賭,你的控制器已經'返回查看()'而不是'返回查看(模型)' – Jonesopolis
你能告訴我們的控制器,調用查看和發送模型參數? – Max