After Submit TotalPages Throws error

大兔子大兔子 提交于 2019-12-12 02:44:21

问题


I have a little problem with my paging ("double TotalPage = @ViewBag.TotalPages; on Partial View"), after submiting on Create or Edit the paging throws the following error: "Cannot convert null to 'double' because it is a non-nullable value type". I have created a partial view that contains the list (Crud Operations using Ajax), all works fine, I can go to different pages in the list but when I submit a new row or edit an existing one it displays that error. Here is the code for it:

public ActionResult IndexApp(string Page)
    {
        var appc = objBs.appointmentdiaryBs.GetALL();
        appc = from ac in db.tbl_Appoiment_Diary
             select ac;
        ViewBag.TotalPages = Math.Ceiling(objBs.appointmentdiaryBs.GetALL().Count() / 5.0);
        int page = int.Parse(Page == null ? "1" : Page);
        ViewBag.Page = page;
        appc = appc.Skip((page - 1) * 5).Take(5);
        ViewBag.Count = db.tbl_Appoiment_Diary.SqlQuery("SELECT * FROM dbo.tbl_Appoiment_Diary").Count();
        return View(appc.ToList());
    }

here is the partial view:

@model IEnumerable<BOL3.tbl_Appoiment_Diary>

<div class="table-responsive">
    <table class="table" id="tbl" style="border-collapse: separate; border: solid grey 1px; border-radius: 6px; -moz-border-radius: 6px;">
        <thead>
            <tr style="background-color:aqua">
                <th>
                    @Html.ActionLink("Title", "Title", "IndexApp", new { SortOrder = ViewBag.SortOrder == null ? "Asc" : (ViewBag.SortOrder == "Asc" ? "Des" : "Asc"), SortBy = "Title", page = (ViewBag.Page == null ? "1" : ViewBag.Page) })
                </th>
                <th>
                    @Html.ActionLink("Scheduled Date and Time", "DateTimeScheduled", "IndexApp", new { SortOrder = ViewBag.SortOrder == null ? "Asc" : (ViewBag.SortOrder == "Asc" ? "Des" : "Asc"), SortBy = "DateTimeScheduled", page = (ViewBag.Page == null ? "1" : ViewBag.Page) })
                </th>
                <th>
                    @Html.ActionLink("Appointment Lenght", "AppointmentLenght", "IndexApp", new { SortOrder = ViewBag.SortOrder == null ? "Asc" : (ViewBag.SortOrder == "Asc" ? "Des" : "Asc"), SortBy = "AppointmentLenght", page = (ViewBag.Page == null ? "1" : ViewBag.Page) })
                </th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.DisplayFor(modelItem => item.Title)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.DateTimeScheduled)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.AppointmentLenght)
                    </td>
                    <td style="align-content:center">
                        <a href="@Url.Action("EditApp", "ClientAppoint", new { id = item.ID })" class="editDialog">Edit</a> |
                        @Html.ActionLink("Delete", "Delete", new { id = item.ID })
                    </td>
                </tr>
            }
        </tbody>
    </table>

@{
    double TotalPage = @ViewBag.TotalPages;
}
<ul class="pagination pagination-sm">
    @for (int i = 1; i <= TotalPage; i++)
    {
        if (i == ViewBag.Page)
        {
            <li class="active">@Html.ActionLink(i.ToString() + " ", "IndexApp", new { SortOrder = (ViewBag.SortOrder == null ? "Asc" : ViewBag.SortOrder), SortBy = (ViewBag.SortBy == null ? "Title" : ViewBag.SortBy), Page = i })</li>
        }
        else
        {
            <li>@Html.ActionLink(i.ToString() + " ", "IndexApp", new { SortOrder = (ViewBag.SortOrder == null ? "Asc" : ViewBag.SortOrder), SortBy = (ViewBag.SortBy == null ? "Title" : ViewBag.SortBy), Page = i })</li>
        }
    }
</ul>
</div>

and here is the Index view:

<div id="main-div">
            <div class="clearfix">&nbsp;</div>
            <div class="clearfix">&nbsp;</div>
            <div class="container">                 
                <a href="@Url.Action("Action", "Controller")" id="Add" class="btn btn-primary btn btn-xs">Adauga</a>
                <br />
                <div id="div-record1">
                    @Html.Partial("_Detail")
                </div>
            </div>
        </div>

来源:https://stackoverflow.com/questions/43344924/after-submit-totalpages-throws-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!