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

   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值