Sunteți pe pagina 1din 4

ASP.

NET MVC Music Store


Tutorial
Version 1.0

Jon Galloway - Microsoft


10/8/2010

http://mvcmusicstore.codeplex.com - Licensed under Creative Commons Attribution 3.0 License.


ASP.NET MVC Music Store Tutorial

Contents
Overview..................................................................................................................................................................................................... 3
1. File -> New Project............................................................................................................................................................................. 8
2. Controllers...........................................................................................................................................................................................11
Adding a HomeController .............................................................................................................................................................11
Running the Application................................................................................................................................................................13
Adding a StoreController...............................................................................................................................................................15
3. Views and ViewModels...................................................................................................................................................................20
Using a MasterPage for common site elements ...................................................................................................................20
Adding a StyleSheet.........................................................................................................................................................................22
Adding a View template.................................................................................................................................................................23
Using a ViewModel to pass information to our View.........................................................................................................27
More complex ViewModels for Store Browse and Index.................................................................................................35
Adding Links between pages.......................................................................................................................................................41
4. Models and Data Access.................................................................................................................................................................44
Adding a Database............................................................................................................................................................................44
Creating an Entity Data Model with Entity Framework...................................................................................................46
Querying the Database ...................................................................................................................................................................53
Store Index using a LINQ Query Expression.....................................................................................................................54
Store Browse, Details, and Index using a LINQ Extension Method.........................................................................55
5. Edit Forms and Templating..........................................................................................................................................................59
Customizing the Store Manager Index.....................................................................................................................................60
Scaffold View templates............................................................................................................................................................61
Using a custom HTML Helper to truncate text ................................................................................................................65
Creating the Edit View....................................................................................................................................................................68
Implementing the Edit Action Methods..............................................................................................................................69
Writing the HTTP-GET Edit Controller Action.................................................................................................................70
Creating the Edit View...............................................................................................................................................................70
Using an Editor Template.........................................................................................................................................................73
Creating a Shared Album Editor Template .......................................................................................................................75

MVC Music Store Tutorial v1.0 – http://mvcmusicstore.codeplex.com – Tutorial under Creative Commons Attribution 3.0 License
Page 1
Creating the StoreManagerViewModel...............................................................................................................................78
Updating the Edit View to display the StoreManagerViewModel............................................................................79
Implementing Dropdowns on the Album Editor Template........................................................................................80
Implementing the HTTP-POST Edit Action Method......................................................................................................82
Implementing the Create Action............................................................................................................................................85
Implementing the HTTP-GET Create Action Method....................................................................................................85
Handling Deletion.............................................................................................................................................................................90
6. Using Data Annotations for Model Validation ......................................................................................................................98
Using MetaData Partial Classes with Entity Framework.............................................................................................98
Adding Validation to our Album Forms..............................................................................................................................99
Using Client-Side Validation.................................................................................................................................................103
7. Membership and Authorization...............................................................................................................................................107
Adding the AccountController and Views ...........................................................................................................................107
Adding an Administrative User with the ASP.NET Configuration site ....................................................................108
Role-based Authorization ..........................................................................................................................................................113
8. Shopping Cart with Ajax Updates ...........................................................................................................................................115
Managing the Shopping Cart business logic.......................................................................................................................115
The Shopping Cart Controller...................................................................................................................................................119
Ajax Updates using Ajax.ActionLink ......................................................................................................................................122
9. Registration and Checkout.........................................................................................................................................................130
Migrating the Shopping Cart.....................................................................................................................................................133
Creating the CheckoutController ............................................................................................................................................135
Adding the AddressAndPayment view.................................................................................................................................140
Defining validation rules for the Order ................................................................................................................................142
Adding the Checkout Complete view.....................................................................................................................................144
Adding The Error view................................................................................................................................................................146
10. Final updates to Navigation and Site Design ...................................................................................................................148
Creating the Shopping Cart Summary Partial View ........................................................................................................148
Creating the Genre Menu Partial View .................................................................................................................................150
Updating Site master to display our Partial Views..........................................................................................................152
Update to the Store Browse page............................................................................................................................................153
Updating the Home Page to show Top Selling Albums..................................................................................................154
Conclusion.............................................................................................................................................................................................157

MVC Music Store Tutorial v1.0 – http://mvcmusicstore.codeplex.com – Tutorial under Creative Commons Attribution 3.0 License
Page 2
Thank you for trying GIRDAC PDF to Word Converter.
Trial version converts few pages from forty PDF files.
If you are satisfied with this conversion,
you can order PDF to Word Converter from
http://www.girdac.com/Products/Buy.htm

S-ar putea să vă placă și