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}) 在页面中添加动态链接

       

  • 相关阅读:
    C语言基本快速入门教程
    几何深度学习前沿
    Anaconda 更改清华源
    大学安全教育-实验室安全测试题库
    《如何写好科研论文》(清华)慕课答案
    集群考试试卷
    集群考试相关
    Linux下tar压缩解压用法
    2020-安全微课(新生入学教育)答案
    函数用法和底层分析
  • 原文地址:https://www.cnblogs.com/imihiroblog/p/2588786.html
Copyright © 2011-2022 走看看