【问题标题】:MVC 4 Controller Reference IssueMVC 4 控制器参考问题
【发布时间】:2013-08-14 15:13:11
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Test.Models;

namespace Test.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = new DropDownListData();
            model.DropDownListItems.Add(new SelectListItem { Text = "Sun", Value = "1" });
            return View(model);
        }
    }
}

这么说

System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem> 不包含“添加”的定义,并且找不到接受System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem> 类型的第一个参数的扩展方法“添加”(您是否缺少 using 指令或程序集引用?)

我缺少什么参考资料?

【问题讨论】:

  • 你的model.DropDownListItems属性是什么类型的?

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


【解决方案1】:

正如错误试图告诉你的那样,IEnumerable<T> 是一个只读集合类型。

如果您想改变集合,请将其更改为List<T>

【讨论】:

  • 这是正确答案。优秀的! :) 我不能再接受 10 分钟的回答,但我会接受的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-09
  • 1970-01-01
  • 2018-04-16
  • 2014-06-25
相关资源
最近更新 更多