控制器将ViewBag模型拆分为具有数据库参数的多个页面正在跳过记录

时间:2014-12-23 11:39:26

标签: javascript asp.net asp.net-mvc razor

摘要:按页数限制将服务列表分成多个页面会丢失两个页面之间的记录。无论使用Razor如何更改,第二页都从相同的ID开始。换句话说,我需要选择第2页的结尾。这可能是一个基本的ASP.net问题。控制器正在错误地查看错误。

我继承了一个项目,无法找到为View设置参数的位置。我无法确定哪个元素导致问题,并且需要指导哪些代码特别包含在包含的内容之外。在收到评论时,我将使用代码或其他细节修改问题,以便尽可能详细地保留问题。

更新注意:项目中没有名为Controllers的文件夹。可以在&bin; \ work1.dll'

中找到对数据库的引用

期望:
有两个墙显示器,每个都有一个内部网页列表"服务",很像机场航站楼列出航班时间。屏幕上的分辨率非常适合5项服务。

有一个SQL表,其参数用于定义" WallSortBy"和#34; ServicesPerPage"。

通过将ServicesPerPage的值从6更改为5," WallDisplay1"应显示服务1-5和" WallDisplay2" 6-10,或者总服务少于10个,只需6- [上次服务]。如果超过10,则在"倒计时"达到60秒后,页面将以Wall1 [6-10],Wall2 [11-15]等循环,或者其他类似的效果。

问题: 以9总服务为例。 (对于其他总计也是如此) 当ServicesPerPage从6更改为5时:

WallDisplay1 = [1 to 5]
WallDisplay2 = [7 to 9]

缺少服务6。

将ServicesPerPage设置为ANYTHING:

WallDisplay1 = [1 to ANYTHING]
WallDisplay2 = [7 to 9]

控制板: 仪表板工作正常,使用与每个"服务"的墙显示相同的视图布局。 所有9条记录都正确显示。

WallDisplay1: WallDisplay1 WallDisplay2: WallDisplay2

我已经在整个项目中搜索了硬编码的6和7,并且没有找到。我看不到对SQL表的任何引用,该表通过表的名称存储参数。 (更新:在bin \ work1.dll中有多个引用) web.config中的连接字符串具有数据库,但在整个项目中,表名不在我能找到的任何地方。两者都不是" ServicesPerPage",并且SQL表中该参数的id是一个哈希id。

我在绑定模型上阅读的示例并没有将多个页面拆分为单独的网页,通常这些示例使用导航器从单个网页显示页面。

ViewBag按" Location"排序,表示服务的位置不要与属性" windows.location"混淆。

有三个Razor .vbhtml页面将ViewBag与服务列表一起使用: Dashboard.vbhtml, WallDisplay1.vbhtml, WallDisplay2.vbhtml

相关信息中心代码:

@ModelType IEnumerable(Of work1.Service)

@code
    ViewData("Title") = "Board"

    Dim lstServiceStatus As SelectList
    lstServiceStatus = New SelectList(ViewBag.lstServiceStatus, "Value", "Text", ViewBag.viewStatus)

     Dim SortBy As String = If(HttpContext.Current.Request.QueryString("SortBy") Is Nothing, "Location", _
                               HttpContext.Current.Request.QueryString("SortBy"))
     Dim viewStatus As String = If(HttpContext.Current.Request.QueryString("viewStatus") Is Nothing, "Active", _
                                  HttpContext.Current.Request.QueryString("viewStatus"))

End Code

<div id="divBoard">
    <div style="margin: 0px 0px 8px 0px;">
        <div style="display:inline-table; margin:0px 0px 4px 0px">
            Sort by: 
            @If ViewBag.sortby = "Date" Then
                @Html.ActionLink("Location", "Dashboard", New With {.SortBy = "Location", .viewStatus = viewStatus})
                @<span style="font-weight:bold">/ Date</span> 
            Else
                @<span style="font-weight:bold">Location /</span> 
                @Html.ActionLink("Date", "Dashboard", New With {.SortBy = "Date",.viewStatus=viewStatus})
            End If
        </div>
        <div style="display:inline-table; margin-left:50px;">
            Status:
            @Html.DropDownList("selStatus", lstServiceStatus, New With {.onchange = "javascript:selectViewStatus(this);"})
        </div>
    </div>

    @For Each item In Model

大部分格式化继续,然后结束,保存ID。从这个页面调用其他窗口,这就是它的结束。

    function saveField(th, SrvId) {
        $.post("saveServiceField", {
            FieldName: th.id,
            Value: th.value,
            SrvId: SrvId
        }, function (data) { th.value = data; });
    }

    function selectViewStatus(th) {
        if (getquerystring()["SortBy"] != null) {
            window.location = "/Roster/Dashboard?SortBy=" + getquerystring()["SortBy"] + "&viewStatus=" + th.value;
        }
        else {
            window.location = "/Roster/Dashboard?viewStatus=" + th.value;
        }
    }


    function getquerystring() {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < hashes.length; i++) {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }
        return vars;
    }
</script>

WallDisplays几乎完全相同。

他们之间的区别在于:

WallDisplay1:

<div id="divBoard">
    <div style="margin: 0px 0px 3px 0px;">
        <div style="display: inline-table; margin: 0px 0px 4px 0px">
            Sort by:
            @If ViewBag.sortby = "Date" Then
                @Html.ActionLink("Location", "WallDisplay", New With {.SrvId = Guid.Empty, .SortBy = "Location"})
                @<span style="font-weight: bold">/ Date</span> 
            Else
                @<span style="font-weight: bold">Location /</span> 
                @Html.ActionLink("Date", "WallDisplay", New With {.SrvId = Guid.Empty, .SortBy = "Date"})
            End If
            <input type="hidden" id="hSortBy" value="@ViewBag.SortBy" />
            <input type="hidden" id="hLastSrvId" value="@ViewBag.LastSrvId" />
            <input type="hidden" id="hRefreshTime" value="@ViewBag.RefreshTime" />
             Page @ViewData("currentpage") of @ViewData("totalpage") - Refresh in <span id="countdown_text" style="font-weight: bold">@ViewData("RefreshTime1")</span>  Seconds
             <script type="text/javascript">countdown_init(@ViewData("RefreshTime1"))</script>

        </div>
    </div>
    <script type="text/javascript" language="javascript">
        function loadWall() {
            var str = '/Roster/WallDisplay?SrvId=' + $('#hLastSrvId').attr('value') + '&SortBy=' + $('#hSortBy').attr('value');
            var t = setTimeout("window.location = '" + str + "'", $('#hRefreshTime').attr('value'));
        }
    </script>
    @For Each item In Model

WallDisplay2:

  <input type="hidden" id="hSortBy" value="@ViewBag.SortBy" />
            <input type="hidden" id="hLastSrvId" value="@ViewBag.LastSrvId" />
            <input type="hidden" id="hRefreshTime" value="@ViewBag.RefreshTime" />


    <div id="divBoard" >
    <div style="margin: 0px 0px 3px 0px;">
        <div style="display:inline-table; margin:0px 0px 4px 0px">
            Sort by: 
            @If ViewBag.sortby = "Date" Then
                @Html.ActionLink("Location", "WallDisplay", New With {.SrvId = Guid.Empty, .SortBy = "Location"})
                @<span style="font-weight:bold">/ Date</span> 
            Else
                @<span style="font-weight:bold">Location /</span> 
                @Html.ActionLink("Date", "WallDisplay", New With {.SrvId = Guid.Empty, .SortBy = "Date"})
End If
           Page @ViewData("currentpage2") of @ViewData("totalpage2") - Refresh in <span id="countdown_text" style="font-weight: bold">@ViewData("RefreshTime2")</span>  Seconds
             <script type="text/javascript">countdown_init(@ViewData("RefreshTime2"))</script>
        </div>
    </div>
@If  ViewData("requiredSecondScree")=False Then
    @<strong>All Services are on the first screen...</strong>
Else
      @<script type="text/javascript" language="javascript">
    function loadWall() {
        var str = '/Roster/WallDisplay2?SrvId=' + $('#hLastSrvId').attr('value') + '&SortBy=' + $('#hSortBy').attr('value');
        var t = setTimeout("window.location = '" + str + "'", $('#hRefreshTime').attr('value'));
    }
</script>           
    For Each item In Model

更新注意:所有对LastSrvId的引用都显示在已发布的代码中。

以下是脚本。

Javascript

我会根据要求使用任何更相关的信息或代码快速更新此问题。

更新:为丰富的代码道歉:

JScript1.js 我在&#34; loadWall&#34;项目中找到的唯一实例。上面没有显示过。

var wall1Object = null;

var screenRefresher = {
    wallObject: null,

    setWall1Object: function (obj) {
        this.wallObject = obj;
        alert(this.wallObject);
        wall1Object = obj;
    },

    getWall: function () {
        alert(wall1Object);
    },

    reloadWall1Object: function () {
        console.log(wall1Object);
        if (this.wallObject != null) {
            this.wallObject.location.reload();
            return true;
        }
    }
};
var setWall1Object = function (obj) {
    wall1Object = obj;
    alert(wall1Object);
};
var reloadWall1Object = function () {
    //    wall1Object.location.reload();
    alert(wall1Object);
};

2 个答案:

答案 0 :(得分:2)

经过长时间阅读您的问题后,我认为这是您的问题的原因,如果您可以在项目中找到它,您将看到控制器代码以及基于此值分割页面的逻辑。

@ViewBag.LastSrvId

在项目中找到ViewBag.LastSrvId,您将获得控制器代码,在那里您可以看到逻辑设置页码。 I have seen your code and i can see that page is refreshed based on this viewbag value passed as query string to controller "Roster/WallDisplay2" and in this controller there would be all logic of how your pages will be shown

<强>更新

您的控制器文件夹不在项目中,可以单独编写,并作为dll文件包含在项目中,这就是您无法找到Controller代码和Controller文件夹的原因。

答案 1 :(得分:1)

从我看过的所有内容来看,我认为你的问题在于名册控制器中的WallDisplay2动作。在那里,它根据您的ServicesPerPage错误地提取数据。

您的控制人员不需要进入&#34;控制器&#34;文件夹以便工作。它们可能位于DLL或其他文件夹中。它只需要这样命名,希望能帮助你找到它。

public class RosterController : Controller

行动可能不是WallDisplay1WallDisplay2,而是您正在寻找的内容。你也可以找到像这样使用的那些:

public ActionResult NewAction()
{
  return View("WallDisplay2");
}

另外,请查看写入以下HTML字段的@ViewBag.LastSrvId的值。更新&#34; ServicesPerPage&#34;时确保更改。并从仪表板重新加载。如果它相同,那么可能不会使用&#34; ServicesPerPage&#34;来计算该值。

<input type="hidden" id="hLastSrvId" value="@ViewBag.LastSrvId" />

最后,如果您在没有源代码的情况下在DLL中找到数据库访问代码并在DLL中找到控制器,那么您最好只重写代码以实现分页,这样如果有更多服务获得它可以正常工作添加。当您重新加载WallDisplay2并且根据排序将服务添加到您的上一页时,最后一次关闭LastSrvId将导致同样的问题。