2010年8月

UrlHelper

system.web.mvc

Contains methods to build URLs for ASP.NET MVC within an application.

.Action(string)

摘要:
Generates a fully qualified URL to an action method by using the specified action name.

参数:
actionName: The name of the action method.

返回值:
The fully qualified URL to an action method.

利用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下面四种方法。