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

    Chapter01:

    1). GuestBook

    Index.aspx:

    <form method="post" action="/GuestBook/Sign">
        <fieldset>
            <legend>Guest Book</legend>
            
            <%= Html.Label("Name") %>
            <%= Html.TextBox("Name") %>
            
            <%= Html.Label("Email") %>
            <%= Html.TextBox("Email") %>
            
            <%= Html.Label("Comments") %>
            <%= Html.TextArea("Comments", new { rows=6, cols=30 }) %>
            
            <div>
            <input type="submit" value="Sign" />
            </div>
        </fieldset>
        </form>

    ThankYou.aspx:

    <h2>Thank You!</h2>
        <p>Thank you for signing the guest book!  You entered:</p>
        Name: <%= ViewData["name"] %><br />
        Email: <%= ViewData["email"] %><br />
        Comments: <i><%= ViewData["comments"] %></i>

    GuestBookController.cs:

    public class GuestBookController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
     
            public ActionResult Sign(string name, string email, string comments)
            {
                //do something with the values, such as send an email
     
                ViewData["name"] = name;
                ViewData["email"] = email;
                ViewData["comments"] = comments;
     
                return View("ThankYou");
            }
        }

    2).GuestBookWithModel

    Index.aspx:

    <h2>Sign the Guest Book!</h2>
        
        <% using (Html.BeginForm()) {%>
     
            <fieldset>
                <legend>Fields</legend>
                <p>
                    <%= Html.LabelFor(model => model.Name) %>
                    <%= Html.TextBoxFor(model => model.Name) %>                
                </p>
                <p>
                    <%= Html.LabelFor(model => model.Email) %>
                    <%= Html.TextBoxFor(model => model.Email) %>                
                </p>
                <p>
                    <%= Html.LabelFor(model => model.Comments) %>
                    <%= Html.TextAreaFor(model => model.Comments) %>                
                </p>
                <p>
                    <input type="submit" value="Create" />
                </p>
            </fieldset>
     
        <% } %>    

    ThankYou.aspx:

    <h2>Thank You!</h2>
        
        Thank you for signing our Guest Book.  You entered: <br />
        
        <%= Html.DisplayForModel() %>

    GuestBookController.cs:

    public class GuestBookController : Controller
        {
            public ActionResult Index()
            {
                var model = new GuestBookEntry();
                return View(model);
            }
     
            [HttpPost]
            public ActionResult Index(GuestBookEntry entry)
            {
                //hang on to the submitted value, so we can
                //retrieve it upon redirect
                TempData["entry"] = entry;
                return RedirectToAction("ThankYou");
            }
     
            public ActionResult ThankYou()
            {
                if(TempData["entry"] == null)
                {
                    //somehow they got here without filling out the form
                    return RedirectToAction("index");
                }
     
                var model = (GuestBookEntry) TempData["entry"];
                return View(model);
            }
        }

    GuestBookEntry.cs:

    public class GuestBookEntry
        {
            public string Name { get; set; }
            public string Email { get; set; }
            public string Comments { get; set; }
        }
  • 相关阅读:
    启动Nginx、查看nginx进程、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级
    专为渗透测试人员设计的 Python 工具大合集
    如何为网站启用HTTPS加密传输协议
    正确设置nginx/php-fpm/apache权限 提高网站安全性 防止被挂木马
    java中十进制转换为任意进制
    多线程死锁的产生以及如何避免死锁
    Java Integer和String内存存储
    Java 内存溢出(java.lang.OutOfMemoryError)的常见情况和处理方式总结
    Jvm垃圾回收器详细
    分布式环境中的负载均衡策略
  • 原文地址:https://www.cnblogs.com/RobotTech/p/2120935.html
Copyright © 2011-2022 走看看