问题:我无法访问SelectList中的项目数 我有一个返回SelectList的HtmlHelper方法: public static SelectList FilterSelectList(this HtmlHelper helper, ListStuff eList, string dept){ ListStuff returnList = new ListStuff(); //
我有一个返回SelectList的HtmlHelper方法:
public static SelectList FilterSelectList(this HtmlHelper helper, List<Stuff> eList, string dept) { List<Stuff> returnList = new List<Stuff>(); //Do Stuff return new SelectList(returnList, "ID", "Name"); }
然后我进行了测试,确认过滤器已正确完成:
// Arrange List<Stuff> eList = MVCMocks.GetList(); string dept = "T"; int expectedCount = eList.FindAll(e => e.Dept == dept).Count; // Act var actual = HtmlHelpers.FilterSelectList(helper, eList, dept); // Assert Assert.AreEqual(expectedCount, actual.Count, "The list was not properly filtered.");
调用actual.Count会导致错误.
我希望这只是我的一个愚蠢疏忽的例子,但我一直在敲打这个问题.证明我是对的!