1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 |
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; } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
[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()); } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 |
@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> } |
C#_MVC_分页update,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/MarchThree/p/3754258.html