ASPNETZERO - 基本索引列表视图错误
ASPNETZERO - Basic index list view error
我正在处理 ASPNETZERO .NET Core MVC 模板。我想用图块而不是数据表或 Jtable 网格设置一个简单的索引视图。我正在按照文档 here 中的示例进行操作。我复制了应用服务索引方法的代码。我复制了视图模型代码。然后我将代码应用到我的索引视图 CSHTML。一旦我编写了 foreach 代码行并放入模型。智能感知不显示任何内容。我能够编译代码,但是当我 运行 页面时,我收到如下所示的错误消息。
foreach statement cannot operate on variables of type 'CompanyIndexViewModel' because 'CompanyIndexViewModel' does not contain a public definition for 'GetEnumerator'
我需要一些帮助来解决这个错误。此外,如果有人有代码示例说明我如何使用图块而不是使用网格来显示简单的索引视图,请分享。我有 css/html 的瓷砖看起来工作。我能够创建一个 returns 我实体的列表对象的应用程序服务。我似乎无法弄清楚如何让它在 index.cshtml 页面和相关的 index.js 页面上工作。我已经在 ABP 模板之外做了很多次。我正在努力在 ABP 模板的上下文中完成这项工作。
这是视图模型代码。
[AutoMapFrom(typeof(ListResultDto<CompanyListDto>))]
public class CompanyIndexViewModel
{
public CompanyIndexViewModel(ListResultDto<CompanyListDto> output)
{
output.MapTo(this);
}
}
我暂时找到了解决问题的办法。
我用下面的代码更新了我的视图模型。
[AutoMapFrom(typeof(ListResultDto<CompanyListDto>))]
public class CompanyIndexViewModel
{
public IReadOnlyList<CompanyListDto> Companies { get; }
public CompanyIndexViewModel(IReadOnlyList<CompanyListDto> companies)
{
Companies = companies;
}
}
然后我将我的控制器代码更新到下面。
var output = _companyAppService.GetCompanyList(input);
var model = new CompanyIndexViewModel(output.Items);
return View(model);
我通过阅读这篇文章得到了这个解决方案here
你需要继承ListResultDto<CompanyListDto>
如图here:
[AutoMapFrom(typeof(ListResultDto<CompanyListDto>))]
public class CompanyIndexViewModel : ListResultDto<CompanyListDto>
{
public CompanyIndexViewModel(ListResultDto<CompanyListDto> output)
{
output.MapTo(this);
}
}
然后您可以在Index.cshtml
中访问Model.Items
,如图here:
@foreach (var company in Model.Items)
{
// ...
}
我正在处理 ASPNETZERO .NET Core MVC 模板。我想用图块而不是数据表或 Jtable 网格设置一个简单的索引视图。我正在按照文档 here 中的示例进行操作。我复制了应用服务索引方法的代码。我复制了视图模型代码。然后我将代码应用到我的索引视图 CSHTML。一旦我编写了 foreach 代码行并放入模型。智能感知不显示任何内容。我能够编译代码,但是当我 运行 页面时,我收到如下所示的错误消息。
foreach statement cannot operate on variables of type 'CompanyIndexViewModel' because 'CompanyIndexViewModel' does not contain a public definition for 'GetEnumerator'
我需要一些帮助来解决这个错误。此外,如果有人有代码示例说明我如何使用图块而不是使用网格来显示简单的索引视图,请分享。我有 css/html 的瓷砖看起来工作。我能够创建一个 returns 我实体的列表对象的应用程序服务。我似乎无法弄清楚如何让它在 index.cshtml 页面和相关的 index.js 页面上工作。我已经在 ABP 模板之外做了很多次。我正在努力在 ABP 模板的上下文中完成这项工作。
这是视图模型代码。
[AutoMapFrom(typeof(ListResultDto<CompanyListDto>))]
public class CompanyIndexViewModel
{
public CompanyIndexViewModel(ListResultDto<CompanyListDto> output)
{
output.MapTo(this);
}
}
我暂时找到了解决问题的办法。
我用下面的代码更新了我的视图模型。
[AutoMapFrom(typeof(ListResultDto<CompanyListDto>))]
public class CompanyIndexViewModel
{
public IReadOnlyList<CompanyListDto> Companies { get; }
public CompanyIndexViewModel(IReadOnlyList<CompanyListDto> companies)
{
Companies = companies;
}
}
然后我将我的控制器代码更新到下面。
var output = _companyAppService.GetCompanyList(input);
var model = new CompanyIndexViewModel(output.Items);
return View(model);
我通过阅读这篇文章得到了这个解决方案here
你需要继承ListResultDto<CompanyListDto>
如图here:
[AutoMapFrom(typeof(ListResultDto<CompanyListDto>))]
public class CompanyIndexViewModel : ListResultDto<CompanyListDto>
{
public CompanyIndexViewModel(ListResultDto<CompanyListDto> output)
{
output.MapTo(this);
}
}
然后您可以在Index.cshtml
中访问Model.Items
,如图here:
@foreach (var company in Model.Items)
{
// ...
}