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指令或程序集引用? )
我错过了什么参考?
答案 0 :(得分:2)
由于错误试图告诉您,IEnumerable<T>
是只读集合类型。
如果要改变集合,请将其更改为List<T>
。