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

       

  • 相关阅读:
    SQL Server 删除重复数据只保留一条
    英语冠词有哪些?
    英语基本语法
    统一身份认证服务(客户端用户身份验证)
    解决MVC中使用BundleConfig.RegisterBundles引用Css及js文件发布后丢失的问题
    统一身份认证服务 源码(客户端)
    MVC 如何设定默认默认路由为指定的Area下的某个action(笔记)
    MongoDB安装笔记
    消息队列第二篇:MessageQueue实战(课程订单)
    消息队列第一篇:MessageQueue介绍
  • 原文地址:https://www.cnblogs.com/imihiroblog/p/2588786.html
Copyright © 2011-2022 走看看