zoukankan      html  css  js  c++  java
  • MVC Music Store

    一、Url映射到Controller ActionResult(Method)

    (1)添加StoreController

        public class StoreController : Controller
        {
            //
            // GET: /Store/
            //public ActionResult Index()
            //{
            //    return View();
            //}
            public string Index(string name)                             //理解Url如何对应到Controller
            {
                return HttpUtility.HtmlEncode("Welcome," + name + "!"); //  Store/Index?name=Admin
            }
            public string Browse(string genre)
            {
                return HttpUtility.HtmlEncode("You're Browsing Genre " + genre);//Store/Browse?genre=Jaze
            }
            public string Details(string album)
            {
                return HttpUtility.HtmlEncode("This is the Detail of " + album);//Store/Details?album=爱在西元前
            }
        }

    (2)修改Globe.asax的RegisterRoute方法,让StoreController index成为默认主页

    (3)理解Url如何对应到Controller中的方法:

       

      

     二、ActionResult接收URL, 用View展示处理结果

    再右键ActionResult-->GotoView,修改代码

    三、更改Site.css(设置logo,页面布局)

                说明:_Layout.cshtml文件相当于母页. 

              The content from our individual views will be displayed by the @RenderBody() command, and any common content that we want to appear outside of that can be added to the _Layout.cshtml markup.

    (1)添加3张图片,替换Site.css

      

    (2)在_Layout.cshtml中添加 css引用和 ul li.  (可以删除原来的_Layout.cshtml,再新建一个_Layout.cshtml)

    四、创建Model,Controller中处理Model,用Model向View传值

    (1)添加Album,用DetailView 显示Album细节

        >在Model下添加Album类,包含ID,Name等属性

        >在StoreController中添加Action Details(int albumID)

        >为Details Action 添加View, 在View中 声明接收对象的类型,在View中显示Model对象的信息

      

    (2)添加Genre,用BrowserView显示所有Genre

         >添加Genre类,及主要属性

         >Store C 添加Browse方法, 用list向View传递所有Genre

         >View中显示所有Genre名称

     六、Html.ActionLink(text,ActionName,new{para=value}) 在页面中添加动态链接

       

  • 相关阅读:
    怎么防止重复提交
    如何重新加载 Spring Boot 上的更改,而无需重新启动服务器?
    什么是 JavaConfig?
    Spring Boot 有哪些优点?
    GBK和GB2312编码
    2.补充:计算机表示的单位:
    python中字符串的编码和解码
    Spring Boot 有哪些优点?
    Maven的工程类型有哪些?
    Maven仓库是什么
  • 原文地址:https://www.cnblogs.com/imihiroblog/p/2588786.html
Copyright © 2011-2022 走看看