asp.net mvc中Ajax的实现1

利用Jquery:

这里实现一个最简单的留言板,数据存储在一个List中。

在View中引用Jquery:

添加下面脚本:

Code

创建控制器:

Code [http://www.xueit.com]

public class CommentController : Controller { private IList comments = new List(); public ActionResult Index() { return View(comments); } public ActionResult IndexAjaxHelp() { return View(_comments); } public ActionResult AddComment(string comment) { _comments.Add("2. " comment "
"); return Content(string.Join("\n", _comments.ToArray())); } }

创建View表单:

Code [http://www.xueit.com]

Comments

效果:

3

Ajax Helper。


将最简单的留言板修改成Ajax Helper的方式。

1、首先了解一下Ajax Helper下面四种方法。