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>
}

最新文章

  1. VS2010调试C程序,总是一闪而过
  2. 对于多个列的转行(一个值均匀分布在两个列中),对于个别字段通过取别名,join方式解决。
  3. jquery网站左侧弹出导航菜单
  4. 关于su和su -的区别
  5. TCP/IP笔记 四.应用层(1)——DNS
  6. 循环json数据的列
  7. iOS开发经常使用宏定义
  8. 转载:PHP时间戳 strtotime()使用方法和技巧
  9. idea 连接redis 出现 Caused by: java.net.SocketTimeoutException: connect timed out
  10. IAR中如何定向把数组和函数放在指定的地址单元
  11. C#设计模式六大原则概述
  12. Ajax中返回数据的格式
  13. Java XML JSON 数据解析
  14. Deep learning with Python 学习笔记(6)
  15. 机器学习--boosting家族之XGBoost算法
  16. linux如何安装yum
  17. (总结)Linux下su与su -命令的本质区别
  18. 支付宝支付系统繁忙,请稍后再试(ALI64)错误解决
  19. 这篇 感觉很实用--DJANGO ORM
  20. bzoj 3158 千钧一发 —— 最小割

热门文章

  1. git参考书籍
  2. [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.2
  3. HW6.1
  4. leetcode@ [300] Longest Increasing Subsequence (记忆化搜索)
  5. HDU-4611 Balls Rearrangement 循环节,模拟
  6. HDU-4604 Deque DP
  7. SSH权威指南(转载)
  8. Linux下用hostapd架无线AP
  9. 第十三章、学习 Shell Scripts 条件判断式
  10. hdoj 2098 分拆素数和