【发布时间】:2015-06-16 23:40:09
【问题描述】:
编辑:我已经检查并尝试了很多其他在 SE 上发现的未引用的程序集问题,但我没有发现很多处理应该是内置程序集的问题 (System.Collections.Generic.List<t>)。这使得手动添加或删除引用等变得困难。
我正在尝试从 API 响应构建 PartialView。我已经确认响应正确且格式正确,我的对象正在正确构建,但是当我生成部分视图时,会显示编译错误。
Compiler Error Message: CS0012: The type 'System.Collections.Generic.List`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
这是 Razor 视图:
@using OpsComponent
@model OpsComponent.ComponentData
<div class="row">
<div class="col-md-6">
<ul class="list-group">
@foreach (Data metric in Model.Metrics)
{
<li class="list-group-item">
<span class="badge">@metric.Value</span>
@metric.Key<br/>
</li>
}
</ul>
</div>
</div>
这里是 Data 类的定义:
public class Data
{
public string Key { get; set; }
public string Value { get; set; }
public string Source { get; set; }
public Status Status { get; set; }
}
Status 是一个枚举。我在调试中检查了模型对象在传递给 PartialView 之前是正确且格式正确的,但我得到的不是正确的布局,而是服务器错误屏幕和 500 响应。
在线@foreach (Data metric in Model.Metrics)
完整性操作代码:
public ActionResult ComponentDetail(string id)
{
var data = Client.GetComponentData(id.DecodeBase64ToString());
var partialViewResult = PartialView("_ComponentDetail", data);
return partialViewResult;
}
【问题讨论】:
-
@Bjørn-RogerKringsjå 我添加了一个编辑解释,但我认为与许多其他“未引用”SE 问题相比,这里的挑战在于它们主要处理 a) ReSharper“无法解析符号”错误(不使用 R#),或 b) 用户库,而不是内置类型列表 List
-
您是否尝试添加
@using System.Collections.Generic?
标签: c# asp.net-mvc razor collections iis-express