当前上下文错误中不存在名称

时间:2015-09-23 20:58:40

标签: asp.net-mvc-5

过去曾问过这个问题,但修复程序对我不起作用,所以很抱歉提前重新发布。我输入了**的MenuItems引用,我收到了错误。这很奇怪,因为我在这里多次引用MenuItems并且我没有得到错误。

      public ActionResult AddMenuItems(List<int> MenuItemID)
    {


    //  Need to run through array of MEnuItem ID's and add them to the Followers LIst of MEnuItems
        Follower follower = db.Followers.Find(FollowerID);//Added a property stub hope it makes it work
        // Remove deselected menu items
        follower.MenuItems.Where(m => **!MenuItemId**.Contains(m.MenuItemID)).ToList()
            .ForEach(m => follower.MenuItems.Remove(m));

        // Add newly selected menu items
        var existingMenuItemIds = follower.MenuItems.Select(m => m.MenuItemID).ToList();
        db.MenuItems.Where(m => **MenuItemIds**.Except(existingMenuItemIds).Contains(m.MenuItemID)).ToList()
            .ForEach(m => follower.MenuItems.Add(m));

    }

1 个答案:

答案 0 :(得分:0)

MenuItemId和MenuItemID是两个不同的文字。 C#是区分大小写的语言。您应该使用MenuItemID而不是MenuItemId,这就是您收到错误的原因。