mvc 2.0 ajax microsoftajax.js,MVC4 AspNet MVC下的Ajax / 使用微软提供的Ajax请求脚本 [jquery.unobtrusive-ajax.min.j...

1:新建-->项目-->Web-->ASP.NET MVC 4 Web 应用程序。命名为:Mvc4MicrosoftAjaxDemo

f2eff1e6bef2c38a0c07c66db03f77a1.png

2:新建控制器:在Controllers文件夹上 右键-->添加-->控制器,命名为:HomeController (HomeController .cs)

3ff603f808b87f9488bf8afb92e4f41a.png

3:在控制器HomeController中新增Action: GetDate()

2b65ef29a5872cc0e4771c25889edd04.gif

6a087676c59fa8b19d76e6bb55a32902.gif

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Threading;5 usingSystem.Web;6 usingSystem.Web.Mvc;7

8 namespaceMvc4MicrosoftAjaxDemo.Controllers9 {10 public classHomeController : Controller11 {12 //

13 //GET: /Home/

14

15 publicActionResult Index()16 {17 returnView();18 }19

20 publicActionResult GetDate()21 {22 //休眠1秒钟,监控前台动作

23 Thread.Sleep(1000);24 returnContent(DateTime.Now.ToString());25 }26 }27 }

HomeController.cs

4:新建视图:在HomeController Action:Index上 右键-->添加视图 命名:Index(默认和Action名称一致) (Index.cshtml)

6fb85d92a72a32bb9bcd358344908ebc.png

5:在视图Index中添加以下代码,使用 微软提供的Ajax请求脚本,如下所示:

5.1:添加 jquery-1.8.2.min.js 和 jquery.unobtrusive-ajax.min.js的引用

2b65ef29a5872cc0e4771c25889edd04.gif

6a087676c59fa8b19d76e6bb55a32902.gif

1 @{2 Layout = null;3 }4

5

6

7

8

9

10

Index

11

12

13

14

15

16

MVC 4 Microsoft Ajax Demo

17 @using (Ajax.BeginForm("GetDate", "Home", new AjaxOptions() { Confirm = "你确定要提交吗?", HttpMethod = "post", UpdateTargetId = "result", LoadingElementId = "loading", InsertionMode = InsertionMode.Replace }))18 {19

20 }21

22

23

24

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值