0
public PartialViewResult AllMetalStockItems()
{
var allMetalDtos = this.metalStockRepository.GetAllMetalSotckDtos();
var allMetalViewModels = Mapper.Map<IEnumerable<MetalStockDto>,IEnumerable<MetalStockViewModel>>(allMetalDtos);
return PartialView("_AllMetalStockItems",allMetalViewModels);
}
查看
@model IEnumerable<GlassContract.Models.ViewModels.Warehouse.MetalStockViewModel>
<table>
<tr>
<th>
Metal Id
</th>
<th>
Colour Code
</th>
<th>
Length
</th>
<th>
Quantity In Stock
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.MetalId </td>
<td>@item.ColorCode </td>
<td>@item.Length </td>
<td>@item.QuantityInStock </td>
</tr>
}
</table>
我得到以下信息
對象引用不設置到對象的實例。
第18行:@foreach(在@Model VAR項目)
這裏是CreateMap
public static void ConfigureMetalStockMapping()
{
Mapper.CreateMap<MetalStockDto, MetalStock>();
Mapper.CreateMap<MetalStock, MetalStockDto>();
Mapper.CreateMap<MetalStockViewModel, MetalStockDto>();
Mapper.CreateMap<MetalStockDto, MetalStockViewModel>();
Mapper.CreateMap<IEnumerable<MetalStockDto>, IEnumerable<MetalStockViewModel>>();
Mapper.CreateMap<IEnumerable<MetalStockViewModel>, IEnumerable<MetalStockDto>>();
}
metalStockRepository.GetAllMetalSotckDtos()
正常工作和測試也通過沒有問題。我正在使用Automapper進行映射。
'allMetalViewModels'必須爲'null',因此映射不起作用。你可以發佈'MetalStockDto'和'MetalStockViewModel'模型 –
映射後你檢查模型的值是否包含值? – Aravindan
不是另一個問題。當我在那裏設置斷點時,它永遠不會停在那裏。直接走向錯誤。 –