zoukankan      html  css  js  c++  java
  • C#_MVC_分页update

    private static string getLinkHtml(UrlHelper urlHelper, bool useAjax, string ajaxSuccessFunction, string linkContent, string actionName, string controllerName, RouteValueDictionary routeValues)
            {
                string link = "";
                if (useAjax)
                {
                    link += "<a href="javascript:void(0);"   onclick="javascript:$.post('" + urlHelper.Action(actionName, controllerName) + "',{";
                    //将route放到post表单中
                    foreach (var route in routeValues.Keys)
                    {
                        link += route + ":'" + routeValues[route].ToString() + "',";
                    }
                    if (routeValues.Count > 0)
                    {
                        link = link.Remove(link.Length - 1);
                    }
                    link += "}," + ajaxSuccessFunction + ")" >";
                }
                else
                {
                    link += "<a href="" + urlHelper.Action(actionName, controllerName, routeValues) + "">";
                }
                link += linkContent;
                link += "</a>";
                return link;
            }
    
    [HttpPost]
            public ActionResult GoPage()
            {
                int pageSize = 4;
                int allCount = db.Movies.Count();
                ViewBag.Num = allCount;
                ViewBag.PageSize = pageSize;
                int pageIndex, startIndex, endIndex;
                //获取开始和结束的记录序号
                PagerHelper.GetStartAndEndIndex(allCount, pageSize, out pageIndex, out startIndex, out endIndex);
                //调用存储过程返回指定序号范围的数据
                // return View(db.SelectUserList(startIndex, endIndex));
    
                //var sear = (from m in db.Movies where m.ID >= startIndex && m.ID <= endIndex select m).ToList();
                var sear = db.Movies.OrderBy(m => m.ID).Skip(startIndex).Take(endIndex - startIndex + 1).ToList();
                return View("Index", sear);
                //return View(db.Movies.ToList());
    
            }
    
    @model IEnumerable<MvcTest.Models.Movie>
    @using MvcTest.Extends
    @using MvcTest.HTML
    
    @{
        ViewBag.Title = "Index";
    }
    
    <script src="~/Scripts/jquery-1.7.1.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
    <h2>Index</h2>
    <script type="text/javascript">
    
        function Call() {
            $.post('/Movies', { page: '2' }, OnPageChanged);
        }
    
        //    function Hello() {
        //        alert("hello");
        //    }
    </script>
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <div id="dvOrders">
        <table class="table">
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.Title)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.ReleaseDate)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Genre)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.Price)
                </th>
                <th></th>
            </tr>
    
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @* @Html.DisplayFor(modelItem => item.Title)*@
                        @item.ID
                    </td>
                    <td>
                        @*@Html.DisplayFor(modelItem => item.ReleaseDate,"yyyy-MM-dd")*@
                        @Html.ValueFor(modelItem => item.ReleaseDate, "{0:yyyy-MM-dd}")
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Genre)
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.Price)
                    </td>
                    <td>
                        @Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
                        @Html.ActionLink("Details", "Details", new { id = item.ID }) |
                        @Html.ActionLink("Delete", "Delete", new { id = item.ID })
                    </td>
                </tr>
            }
    
    
        </table>
        @Html.Pager("GoPage", "Movies", new { }, new PagerConfig { TotalRecord = ViewBag.Num, PageSize = ViewBag.PageSize, UseAjax = true, AjaxUpdateTargetID = "dvOrders" })
     
    </div>
    
    <!--
    <input type="button" id="TestList" />
    -->
    
    @section Scripts{
        <script type="text/javascript">
    
            function Format(date) {
    
                return date + "123";
            }
    
    
            function formatNumToDate(value) {
              var now = eval(value.replace(//Date((d+))//gi, "new Date($1)"));///.../gi是用来标记正则开始和结束;是转义符;()标注了正则匹配分组1,$1
              var year = now.getYear() + 1900;
              var month = now.getMonth() + 1;
              var date = now.getDate();
              var hour = now.getHours();
               var minute = now.getMinutes();
               var second = now.getSeconds();
               return year + "-" + compareNine(month) + "-" + compareNine(date) + " " + compareNine(hour) + ":" + compareNine(minute) + ":" + compareNine(second);
           }
    
            $(document).ready(function () {
                function ChangeDateFormat(time) {
                    if (time != null) {
                        var date = new Date(parseInt(time.replace("/Date(", "").replace(")/", ""), 10));
                        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                        return date.getFullYear() + "-" + month + "-" + currentDate;
                    }
                    return "";
                }
                $("#TestList").click(function () {
    
                    $.getJSON("/Movies/GetAllList", {}, function (result) {
                        
                        alert(result);
                        $.each(result, function (i, field) {
                            //var datetime = field.ReleaseDate.formatNumToDate();
                            
                            alert(i + " " + ChangeDateFormat(field.ReleaseDate));
    
                        });
    
    
    
    
    
    
    
                    });
                });
    
    
            });
         </script>
        }
    
  • 相关阅读:
    射极跟随器的设计及参数确定
    三极管放大电路 之共射放大电路参数确定
    allegro生成光绘文件时,通过cam打开,*.drl钻孔文件不识别,为Unknow类型
    allegro 16.6 空心焊盘的制作
    cadence16.6 如何对齐元件
    Allegro中板子边框不封闭导致的z-copy无法用的问题
    Android Thermal-engine
    《万历十五年》--黄仁宇
    USB 接口探测分类
    Android电池电量跳变
  • 原文地址:https://www.cnblogs.com/MarchThree/p/3754258.html
Copyright © 2011-2022 走看看