【问题标题】:Getting error "The type or namespace name 'SelectList' could not be found" even though I have MVC installed, and have the using statement即使我安装了 MVC 并且有 using 语句,也会出现错误“找不到类型或命名空间名称‘SelectList’”
【发布时间】:2019-07-24 16:04:09
【问题描述】:

Git 将一个旧项目从工作中克隆到 VS 2015。在构建项目时,我收到错误

“找不到类型或命名空间名称'SelectList'”

我已打开 nuget 包管理器并确保已安装 asp.net mvc 并且一切顺利。我还在 using 语句的顶部有声明 using System.Web.Mvc;

我通过包管理器更新了 mvc,看看是否有帮助,但我仍然收到错误。

using System.Web.Mvc;
using .....;
using .....;

namespace WorkPermit.Logic
{
    public class RoleService : IDisposable
    {
        public SelectList GetRolesList()
        {
            var roles = _roleManager.Roles.Select(m => new SelectListItem()
            {
                Text = m.Name,
                Value = m.Name,
            }).ToList();
            return new SelectList(roles, "Value", "Text");
        }
    }
}

由于我安装了 mvc 和 using 语句,我很好奇为什么会收到此错误。

【问题讨论】:

    标签: c# asp.net-mvc asp.net-mvc-4 model-view-controller


    【解决方案1】:

    我找到了解决方案。导航到项目的 References 目录,删除并重新添加 System.Web.Mvc 引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-08
      • 1970-01-01
      相关资源
      最近更新 更多