自己做的一个实验,留作备忘,此实例包括扩一下几个文件:
1、MyMovieController.cs
2、Index.aspx
3、ViewUserControl1.ascx
4、movie类
其中MyMovieController.cs不用再说了,代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax; namespace MyMVC.Controllers
{
public class MYMovieController : Controller
{
//
// GET: /MYMovie/ public ActionResult Index()
{
return View();
}
public ActionResult Search(string query, int? page)
{
List<movie> movies = movie.Movies
.Where(r => r.MovieName.Contains(query))
.OrderByDescending(r => r.MovieName)
.Skip((page ?? ) * )
.Take()
.ToList();
if (Request.IsAjaxRequest())
{
int moiveCount=movie.Movies.Where(r => r.MovieName.Contains(query)).Count();
ViewData["totalPage"] = (int)Math.Ceiling(moiveCount / 4d);
ViewData["query"] = query;
return View("ViewUserControl1", movies);
}
else
{
return View();
}
} }
}

MyMovieController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace MyMVC
{
public class movie
{
public string MovieName { get; set; }
public string Category { get; set; } public movie(string movieName, string category)
{
this.MovieName = movieName;
this.Category = category;
} public static List<movie> Movies
{
get
{
return new List<movie>
{
new movie("龙行天下","动作片"),
new movie("虎胆龙威","动作片"),
new movie("龙虎门","动作片"),
new movie("猛龙过江","动作片"),
new movie("龙的传人","动作片"),
new movie("龙之战","动作片"),
new movie("铁甲威龙","动作片"),
new movie("见龙卸甲","动作片")
};
}
}
}
}

movie.cs

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<MyMVC.movie>>" %>

    <table>
<thead>
<tr>
<th>
MovieName
</th>
<th>
Category
</th>
</tr>
</thead>
<tbody>
<% foreach (var item in Model) { %> <tr>
<td>
<%= Html.Encode(item.MovieName) %>
</td>
<td>
<%= Html.Encode(item.Category) %>
</td>
</tr> <% } %>
</tbody> </table> <p>
<%
int totalPage = (int)ViewData["totalPage"];
string query = ViewData["query"].ToString();
for (var i = ; i < totalPage; i++)
{
%>
<a href="#" title="<%=i %>"><%= Html.Encode(i+) %></a>
<%
}
%>
</p>

ViewUserControl1.ascx

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Index</title>
<style type="text/css">
#result table thead tr
{
background-color:#cccccc;
}
</style>
<script src="../../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
//发送异步请求,将结果输出到<div id="result"></div>中
//最后一个参数可以是"html"也可以是"text"
function search(query, page)
{
$.post("/MYMovie/Search", "query=" + query + "&page=" + page, function(data)
{
$("#result").html(data);
$("#result table tbody tr:odd").css("background", "#F5DEB3");
}, "text"
);
//屏蔽超级链接跳转
return false;
} $(function()
{
//为搜索按钮绑定事件
$("#search").click(function()
{
search($("#query").val());
})
//为新生成的分页连接绑定click事件
$("a").live("click", function()
{
search($("#query").val(), $(this).attr("title"));
});
})
</script>
</head>
<body>
<div>
<h2>搜索电影</h2>
<%= Html.TextBox("query") %>
<input type="button" id="search" value="提交" />
<div id="result"></div>
</div>
</body>
</html>

Index.aspx

在ASP.NET MVC中使用Juqery实现页面局部刷新的更多相关文章

  1. 2.ASP.NET MVC 中使用Crystal Report水晶报表

    上一篇,介绍了怎么导出Excel文件,这篇文章介绍在ASP.NET MVC中使用水晶报表. 项目源码下载:https://github.com/caofangsheng93/CrystalReport ...

  2. 关于 ASP.NET MVC 中的视图生成

    在 ASP.NET MVC 中,我们将前端的呈现划分为三个独立的部分来实现,Controller 用来控制用户的操作,View 用来控制呈现的内容,Model 用来表示处理的数据. 从控制器到视图 通 ...

  3. 在Asp.Net MVC 中配置 Serilog

    Serilog 是一种非常简便记录log 的处理方式,使用Serilog可以生成本地的text文件, 也可以通过 Seq 来在Web界面中查看具体的log内容. 接下来就简单的介绍一下在Asp.Net ...

  4. 如何在 ASP.NET MVC 中集成 AngularJS(3)

    今天来为大家介绍如何在 ASP.NET MVC 中集成 AngularJS 的最后一部分内容. 调试路由表 - HTML 缓存清除 就在我以为示例应用程序完成之后,我意识到,我必须提供两个版本的路由表 ...

  5. 如何在 ASP.NET MVC 中集成 AngularJS(2)

    在如何在 ASP.NET MVC 中集成 AngularJS(1)中,我们介绍了 ASP.NET MVC 捆绑和压缩.应用程序版本自动刷新和工程构建等内容. 下面介绍如何在 ASP.NET MVC 中 ...

  6. 《Entity Framework 6 Recipes》中文翻译系列 (20) -----第四章 ASP.NET MVC中使用实体框架之在MVC中构建一个CRUD示例

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 第四章  ASP.NET MVC中使用实体框架 ASP.NET是一个免费的Web框架 ...

  7. asp.net mvc 中 一种简单的 URL 重写

    asp.net mvc 中 一种简单的 URL 重写 Intro 在项目中想增加一个公告的功能,但是又不想直接用默认带的那种路由,感觉好low逼,想弄成那种伪静态化的路由 (别问我为什么不直接静态化, ...

  8. 在 ASP.NET MVC 中充分利用 WebGrid (microsoft 官方示例)

    在 ASP.NET MVC 中充分利用 WebGrid https://msdn.microsoft.com/zh-cn/magazine/hh288075.aspx Stuart Leeks 下载代 ...

  9. ASP.NET MVC中的两个Action之间值的传递--TempData

    一. ASP.NET MVC中的TempData 在ASP.NET MVC框架的ControllerBase中存在一个叫做TempData的Property,它的类型为TempDataDictiona ...

随机推荐

  1. java中 sleep 与 wait 的区别

    1.所属类不同 sleep是Thread类的方法: wait是Object类的方法: 2.功能不同 sleep是线程用来控制自身流程的,在调用sleep()方法的过程中,线程不会释放对象锁: wait ...

  2. Python全栈开发day6

    1. 简介 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序媛们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引 ...

  3. FreeMaker实现变量求和

        今天在项目上遇到统计分页页面的某个字段的总和,前台页面是使用FreeMaker实现的,记录一下: <#assign tprice = 0 > <#list orderlist ...

  4. DWT小波变换及其在时间序列数据预测中的应用

    Given data: 时间序列数据. Goal:做预测 方法:在滑动窗口中取DWT特征,并验证. 实验验证: Load forcast 数据集. 问题: 小波变换的物理意义是什么? 小波变换的数学意 ...

  5. hihoCoder #1199 : Tower Defense Game ——(树型dp)

    题目链接:https://hihocoder.com/problemset/problem/1199. 题意:一棵以1为根的树,每个点有一个p值和q值,到这个点需要当前分数大于等于p,然后消耗掉(p- ...

  6. 多线程爬取 threading.Thread 文件名支持gbk编码

    # - *- coding:utf-8-*-import urllib2import reimport osimport threadingimport sysreload(sys)sys.setde ...

  7. ubuntu 下搭建nginx

    1.安装nginx sudo apt-get install nginx 2.nginx 的启动和关闭启动 nginx:# nginx -c /etc/nginx/nginx.conf 3.关闭 ng ...

  8. python之路——面向对象(基础篇)

    面向对象编程:类,对象 面向对象编程是一种编程方式,此编程方式的落地需要使用 "类" 和 "对象" 来实现,所以,面向对象编程其实就是对 "类&quo ...

  9. c++总结01

    今天编写了四个小程序分别是“石头剪刀布游戏”“数字之间加空格输出”“蛇形矩阵”“螺旋矩阵”. 通过编写石头剪刀布代码 熟悉了switch语句和if语句的使用,同时也运用了do..while语句,其中 ...

  10. app进入后台之后接收到通知,点进去进入新的页面,再次进入后台,再点击通知进入页面(,两次通过通知进入的页面,创建了两次,会多一个页面,)解决办法监听

    在点击通知进入的页面的 //UIApplicationWillResignActiveNotification是app即将进入后台的方法 //增加监听使它在进入后台之前pop上一个页面 - (void ...