MVC_Ajax请求

MVC_Ajax请求
MVC中的AJAX操作原理还是基于Jquery的封装操作。但是吧没有那么恐怖。
Ajax.BeginForm:使用Ajax.BeginForm方法会生成一个form表单,最后以Ajax的方式提交表单数据;需要用using把该方法括起来,使系统知道form表单从何处开始,何处结束。

 

public class UsersController : Controller
{
//
// GET: /Users/

public ActionResult Index()  //需要添加视图下面有详解
{
return View();
}

public ActionResult Add() //创建一个强类型视图
{
return View();
}

public ActionResult GetData()
{
System.Threading.Thread.Sleep(2000);
return Content(DateTime.Now.ToString());
}

}

添加的Index视图(Razor)

<div>

@using (Ajax.BeginForm("GetData", new AjaxOptions()
{

HttpMethod = "post",
Confirm = "确认获取吗?",
UpdateTargetId = "h",
LoadingElementId = "loading",
InsertionMode = InsertionMode.Replace,
OnSuccess = "upcolor()"

 

}))
{
<input type="submit" name="name" value="GetDateTime" />
}

 

</div>

posted @ 2016-10-20 22:00  路边有一棵草  阅读(355)  评论(0编辑  收藏  举报