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

       

  • 相关阅读:
    vs code快捷键
    封装一个运动函数
    关于数组操作方式的总结
    学习html/css基础的重点笔记
    web新手——新闻列表这样写不容易出错
    AppCan——生成Web/微信App版,调用微信JSAPI支付方式,提示WeixinJSBridge内置对象undefined
    vue slot 占位符
    vue /deep/ css 不用1级1级找了
    vue 双向绑定 2个{{}}
    axios 请求接口 f12可以返回值 但是控制台打印报错
  • 原文地址:https://www.cnblogs.com/imihiroblog/p/2588786.html
Copyright © 2011-2022 走看看