ASP.NET MVC2 in Action 读书笔记 [122] 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>");
        }
    }
原文地址:https://www.cnblogs.com/RobotTech/p/2126934.html