MVC Music Store

Source: Internet
Author: User

 

1. url ing to Controller actionresult (method)

(1) Add storecontroller

     Public   Class  Storecontroller: controller {  //          //  Get:/store/  //  Public actionresult index ()  //  {  //  Return view ();  // }          Public   String Index ( String Name) //  Understand how URLs correspond to Controllers  {  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  " + Album ); //  Store/details? Album = love in the West Region  }} 

(2) modify the registerroute method of globe. asax to make storecontroller index the default homepage.

 

(3) understand how a URL corresponds to a method in the controller:

 

2. The actionresult receives the URL and displays the processing result with the view.

 

Right-click actionresult --> gotoview and modifyCode

Site.css (set the logo and page layout)

Note: The _ layout. cshtml file is equivalent to the parent page.

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 images for site.css

 

(2) Add CSS reference and UL Li in _ layout. cshtml (you can delete the original _ layout. cshtml and create another _ layout. cshtml)

 

4. Create a model. The controller processes the model and uses the model to transmit values to the view.

(1) Add album and use detailview to display album details

> Add the album class under the model, including attributes such as ID and name.

> Add action details (INT albumid) to storecontroller)

> Add a view for the details action, declare the type of the received object in the view, and display the information of the model object in the view.

 

(2) Add genre and use browserview to display all genre

> Add genre class and main attributes

> Store C adds the Browse method and transmits all genre to the view using list

> View displays all genre names

 

 

6. html. actionlink (text, actionname, new {para = value}) Add dynamic links to the page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.