C# Web API-此模型项字典需要类型';System.Collections.Generic.IEnumerable

C# Web API-此模型项字典需要类型';System.Collections.Generic.IEnumerable,c#,json,asp.net-web-api,C#,Json,Asp.net Web Api,尝试查看我的索引视图时出现以下错误: 传递到字典的模型项的类型为“TrackingService.WebReferences.GetSOStsRes+Rootobject”,但此字典需要类型为“System.Collections.Generic.IEnumerable”“1[TrackingService.WebReferences.GetInvBalRes+Body]”的模型项 Index.cshtml @model IEnumerable<TrackingService.WebRef

尝试查看我的索引视图时出现以下错误:

传递到字典的模型项的类型为“TrackingService.WebReferences.GetSOStsRes+Rootobject”,但此字典需要类型为“System.Collections.Generic.IEnumerable”“1[TrackingService.WebReferences.GetInvBalRes+Body]”的模型项

Index.cshtml

@model IEnumerable<TrackingService.WebReferences.GetInvBalRes.Body>

<div>
    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.RecvDt)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Location)
            </th>
        </tr>

        @foreach (var item in Model)
        {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.RecvDt)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Location)
        </td>
    </tr>
                }
        </table>
</div>
Model.cs

public class GetInvBalRes
    {
        public class Rootobject
        {
            public Header header { get; set; }
            public Body[] body { get; set; }
        }

        public class Header
        {
            public string Token { get; set; }
            public string DtTime { get; set; }
            public string ResultCode { get; set; }
            public string ResultMsg { get; set; }
        }

        public class Body
        {
            public string WarehouseCode { get; set; }
            public string CompanyCode { get; set; }
            public string Location { get; set; }
            public string SKU { get; set; }
            public string OnHandQty { get; set; }
            public string InventorySts { get; set; }
            public string LPN { get; set; }
            public string Lot01 { get; set; }
            public string Lot02 { get; set; }
            public string Lot03 { get; set; }
            public string Lot04 { get; set; }
            public string Lot05 { get; set; }
            public string ExpiryDt { get; set; }
            public string ManufactureDt { get; set; }
            public string RecvDt { get; set; }
            public string Hold { get; set; }
        }

    }

您的问题是类型不匹配:

@model IEnumerable<TrackingService.WebReferences.GetInvBalRes.Body>
因此,您可以将视图中的预期模型类型更改为

@model TrackingService.WebReferences.GetInvBalRes.RootObject
或者从代码中返回正确的类型

@model IEnumerable<TrackingService.WebReferences.GetInvBalRes.Body>
var data = JsonConvert.DeserializeObject<Rootobject>(r);
return View(data);
@model TrackingService.WebReferences.GetInvBalRes.RootObject