C# 对象引用未设置为对象asp.net c的实例#

C# 对象引用未设置为对象asp.net c的实例#,c#,asp.net,razor,asp.net-mvc-5,C#,Asp.net,Razor,Asp.net Mvc 5,我已经在我的用户页面上创建了一个表格,显示了他们关注的所有餐厅。但是当我运行页面时,我收到错误对象引用未设置为对象的实例。对于行 @foreach (var RestaurantSearch in Model.RestaurantSearch) 是否有其他编写此代码的方法 个人资料页面代码 @foreach (var RestaurantSearch in Model.RestaurantSearch) { var manager = new UserM

我已经在我的用户页面上创建了一个表格,显示了他们关注的所有餐厅。但是当我运行页面时,我收到错误
对象引用未设置为对象的实例。
对于行

@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>
@foreach(Model.RestaurantSearch中的var RestaurantSearch)
{
var manager=newusermanager(newuserstore(newapplicationdbcontext());
var currentUser=manager.FindById(User.Identity.GetUserId());
if(RestaurantSearch.User1ID==@currentUser.Id)
{ 
@DisplayFor(modelItem=>RestaurantSearch.RestaurantID)
@DisplayFor(modelItem=>RestaurantSearch.User1ID)
@ActionLink(“详细信息”、“详细信息”、“餐厅”,新{id=RestaurantSearch.RestaurantID},null)|
}
}
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; }
    }
公共类Followviewmodel
{
公共IEnumerable用户搜索{get;set;}
公共IEnumerable RestaurantSearch{get;set;}
公共字符串名称{get;set;}
公共字符串{get;set;}
公共字符串名{get;set;}
公共字符串LastName{get;set;}
公共字符串用户名{get;set;}
}

您的
模型或
模型。RestaurantSearch
为空。您必须在控制器操作中设置它

样本:

public ActionResult Index()
{
    Followviewmodel model = new Followviewmodel();

    // fill in the fields
    model.RestaurantSearch = ...

    return View(model);
}

您的
Model
Model.RestaurantSearch
为空。您必须在控制器操作中设置它

样本:

public ActionResult Index()
{
    Followviewmodel model = new Followviewmodel();

    // fill in the fields
    model.RestaurantSearch = ...

    return View(model);
}

我打赌你的控制器有
return View()
而不是
return View(model)
你能给我们展示控制器吗,调用视图并发送模型作为参数?我打赌你的控制器有
return View()
而不是
return View(model)
你能给我们展示控制器吗,调用视图并发送模型作为参数?