尝试调用相关的PageList视图时,视图返回错误

时间:2019-05-27 09:24:39

标签: asp.net-mvc pagedlist

我的视图中有一个错误,该错误调用了另一个包含Pagedlist的ActionResult。在当前页面中,我选择一个“付款频率”,这将重定向到一个在选定期间内执行“付款运行”的视图。当我选择工资频率后运行工资单时,我得到'IPagedList'不包含'PayDayId'的定义,并且找不到扩展方法'PayDayId'接受类型为'IPagedList'的第一个参数(您是否丢失了?使用指令或程序集

在ChoosePayCode.cshtml中,我有:

@model MMM_SYSTEM.Models.PayRun.PayRun
  ...
   <div class="form-group">
                                @Html.LabelFor(model => model.PayDayId, htmlAttributes: new { @class = "control-label col-md-2" })
                                <div class="col-md-5">
                                    @Html.DropDownListFor(m => m.PayDayId, Model.PayDayCodes, "Please Select", htmlAttributes: new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.PayDayId, "", new { @class = "text-danger" })
                                </div>
                            </div>

我已经有用于分页的Nuget程序包,它们在相关视图中被引用如下(PayRun.cshtml):

    @using PagedList;
@model IPagedList<MIHR_SYSTEM.Models.PayRun.PayRun>
<div id="wrapper">
 @if (Model.Count() <= 0)
                                {
                                    <tr> <td colspan="3"> No record found </td> </tr>
                                }
                                else
                                {

                                    foreach (var item in Model)
                                    {
                                        <tr>
                                            <td>@Html.DisplayFor(modelItem => item.EmployeeNumber)</td>
                                            <td>@Html.DisplayFor(modelItem => item.PayDayDate)</td>
                                            <td>@Html.DisplayFor(modelItem => item.GrossPay)</td>

                                        </tr>
                                    }
                                } 
 @Html.PagedListPager(Model, PageNumber => Url.Action("Index", new { 
PageNumber }))
</div>

我曾尝试如下修改ChoosePayCode.cshtml,但错误仍然存​​在,Instaed Razor显示在这种情况下它无法应用索引:

 <th>
      @Html.LabelFor(model => model[0].PayDayId, htmlAttributes: new { @class = "control-label col-md-2" })
  </th>

在控制器中,我有:

 public ActionResult Payroll(int? PageNumber)
List<Models.PayRun.PayRun> payruns = new List<Models.PayRun.PayRun>();
    {        
using (SqlConnection conn = new SqlConnection(Helpers.DatabaseConnect))
        {

        ...
        ...
          conn.Open();
                    cmd.ExecuteNonQuery();

                }


                payruns.Add(payrun);
            }

            conn.Close();
        }

        IPagedList<Models.PayRun.PayRun> payrunss = payruns.ToPagedList(PageNumber ?? 1, 8);

        return View(payrunss);
    }

我已经搜索了许多资料,但是我仍然无法找到错误的地方。关于我应该在哪里更改的任何建议?

0 个答案:

没有答案
相关问题