ASP.NET MVC2 in Action 读书笔记 [12-2] Ajax with MVC

Index.aspx:

<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
    
    <script type="text/javascript">
        function getMessage() {
            $.get("/SimpleAjax/GetMessage", function(data) {
                $("#result").html(data);
            });
        }
    </script>
 
<button type="button" onclick="getMessage();">Get the Message!</button>
<div id="result"></div>

 

SimpleAjaxController.cs:

public class SimpleAjaxController : Controller
    {   
        public ActionResult Index()
        {
            return View();
        }
 
        public ActionResult GetMessage()
        {
            return Content("<h1>This is a custom message returned from an action.</h1>");
        }
    }
posted @ 2011-08-04 09:31  RobotTech  阅读(184)  评论(0编辑  收藏  举报