zoukankan      html  css  js  c++  java
  • ASP.NET MVC2 in Action 读书笔记 [124] MVC Ajax Helpers

    Index.aspx:

    <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
        <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
     
        <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
     
     
    <h3>Ajax.BeginForm</h3>
        
        <h4>Comments</h4>    
        <ul id="comments">        
        </ul>
        
        <% using(Ajax.BeginForm("AddComment", new AjaxOptions
                                                {
                                                    HttpMethod = "POST", 
                                                    UpdateTargetId = "comments",
                                                    InsertionMode = InsertionMode.InsertAfter                                                
                                                })) { %>
        
            <%= Html.TextArea("Comment", new{rows=5, cols=50}) %>
            <button type="submit">Add Comment</button>
                                                
        <% } %>
        
        <h3>Ajax.Link</h3>
        
        <%= Ajax.ActionLink("Show the privacy Policy", "PrivacyPolicy", 
            new AjaxOptions{InsertionMode = InsertionMode.Replace, UpdateTargetId = "privacy"}) %>
     
        <div id="privacy"></div>

    AjaxHelpersController.cs:

    public class AjaxHelpersController : Controller
        {
            private IList<string> _comments = new List<string>();
     
            public ActionResult Index()
            {
                return View(_comments);
            }
     
            [HttpPost]
            public ActionResult AddComment(string comment)
            {
                _comments.Add("<li>" + comment + "</li>");
                return Content(string.Join("\n", _comments.ToArray()));
            }
     
            public ActionResult PrivacyPolicy()
            {
                const string privacyText = @"
                    <h2>Our Commitment To Privacy</h2>
                    Your privacy is important to us. To better protect your privacy we provide this notice explaining our online 
                    information practices and the choices you can make about the way your information is collected and used. 
                    To make this notice easy to find, we make it available on our homepage and at every point where personally 
                    identifiable information may be requested.";
     
                return Content(privacyText, "text/html");
            }
        }
  • 相关阅读:
    51Nod-1006【LCS】+【输出路径】模板题
    POJ 2250 Compromise【LCS】+输出路径
    洛谷 P1387 最大正方形 【dp】(经典)
    【hdu】4521 小明序列【LIS变种】【间隔至少为d】
    HDU 1025 城市供应 【LIS】
    hdu 2191 悼念512汶川大地震遇难同胞 【多重背包】(模板题)
    HDU 2159 FATE【二维完全背包】
    POJ 1384 Piggy-Bank【完全背包】+【恰好完全装满】(可达性DP)
    洛谷 P1474 货币系统 Money Systems(经典)【完全背包】+【恰好装满的最大方案数量】
    洛谷 P1057 传球游戏 【dp】(经典)
  • 原文地址:https://www.cnblogs.com/RobotTech/p/2126953.html
Copyright © 2011-2022 走看看