【发布时间】:2012-10-03 12:42:05
【问题描述】:
在将IEnumerable<string> 类型的模型发送到我在 NancyFX 中的 Razor 视图时,我收到了 YSOD。如果提供一个字符串作为模型,一切都很好,视图中有相关的@model 语句,所以 its 工作。
错误是
无法发现名为 System.Collections.Generic.IEnumerable 的模型的 CLR 类型。确保传递给视图的模型可分配给视图中声明的模型。
我错过了什么?
View.cshtml
@model System.Collections.Generic.IEnumerable<System.String>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1></h1>
@foreach (var item in Model)
{
<h3>@item</h3>
}
</body>
</html>
模块
public class MyModule: NancyModule
{
public MyModule()
{
Get["/"] = parameters => View["View", this.GetModel()];
}
private IEnumerable<string> GetModel()
{
return new[] { "one", "two" };
}
}
【问题讨论】: