简体   繁体   中英

Display Records List in View Obtained from Stored Procedure MVC-4

I am trying to show the List of Records Obtained from database through stored procedure,

I am unable to list the records at view in mvc-4 application.

Here is the existing code

   public ActionResult Report_OrderAnalysisDetail(string Status)
        {
               var AnalysisDetail= db.Report_OrderAnalysisDetail(0,25,0,null,null,null,null,null,Status,null);

               return View(AnalysisDetail);
        }

Here is the Full View:

@model IList<Agorz_MVCApplication.Models.Report_OrderAnalysisDetail_Result>
<div class="content-wrapper" style="min-height: 1000px;">
    <section class="content-header">
        <h1 class="page-header">Order Analysis Detail</h1>
    </section>
    <div id="RenderPartial" name="RenderPartial" style="min-height:950px;important">
        @Html.Partial("_Report_OrderAnalysisDetail")

    </div>
</div>

Here is the partial view in which i want to iterate the records:

@model IList<Agorz_MVCApplication.Models.Report_OrderAnalysisDetail_Result>
  @foreach (var item in Model)
    {
        <tr class="gradeX odd" role="row">

            <td class="center">@item.OrderId</td>
            <td class="center">@if(item.OrderDate!=null){@item.OrderDate.Value.ToShortDateString()}</td>
            <td class="center">@item.ServiceRequested</td>
            <td class="center">@item.ServiceProvider</td>
            <td class="center">@item.Customer</td>
            <td class="center">@item.OrderStatus</td>

        </tr>
    }

when i run the code and view is loaded it gives the following error.

Server Error in '/' Application.

The model item passed into the dictionary is of type 'System.Data.Objects.ObjectResult'1[Agorz_MVCApplication.Models.Report_OrderAnalysisDetail_Result]', but this dictionary requires a model item of type 'System.Collections.Generic.IList'1[Agorz_MVCApplication.Models.Report_OrderAnalysisDetail_Result]'.

var AnalysisDetail= db.Report_OrderAnalysisDetail(0,25,0,null,null,null,null,null,Status,null).ToList();

在sp返回一个对象的末尾添加ToList() ,并且您在视图中提供了List类型

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM