利用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("

  • " comment "
  • ");
    return Content(string.Join("\n", _comments.ToArray()));
    }

    }

    创建View表单:

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

    Comments




    <% using (Html.BeginForm("AddComment","Comment",FormMethod.Post,new {@class="hijax"})) { %>
    <%= Html.TextArea("Comment", new{rows=5, cols=50}) %>


    <% } %>

    效果:
    3 

    Ajax Helper。

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

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

    标签: none

    添加新评论