Introduction to MVC
Lesson 3 - Visual Studio
[WHAT]
- ] VIDEO SUMMARY - summary notes on the video, this lesson explains more about how the features in the VS IDE can help you to build out your applications.
[WHY]
- ] about the features and benefits in the VS IDE
[WHERE]
- ] WATCH THE FULL VIDEO
-
[WHEN]
- ] 2014-06-24 - produced
[EXAMPLE]
- [00:00] review of previous lesson
- ] was trying to AVOID the "entity framework" and "code first" conversation, wanted to just let the magic happen, the magic didnt happen, tried all of the usual things() to fix the problem, nothing worked, usually it does work
- ] model is a class
- ] how you/users are going to interact with the class are by going in adding attributes
- ] concept of model binding
- ] will automatically handle a lot of stuff for us
- [02:00] MV VM - viewModels
- ] another pattern
- ] how we are going to structure our data for display is
- ]
- [09:30] the power of visual studio(VS)
- ] making it easier to generate the code,
- ] will look at scaffolding, ef, vs web tools
- [11:00] scaffolding
- ] generates controllers and views code based upon models
- ] built with common asp.net scaffolding system
- ] originally was different versions of scaffolding for mvc, forms, api, now 1 version
- ] how to - right click, controllers, select add scaffolded item
- ] select - type of controller, (empty, ef, read/write, ...)
- ] option - use asynch controller actions - if your controllers are making a lot of requests, asynch requests can perform non blocking io, aka 2nd task will start before first task is complete, better performance
- ] option - generate views -
- ] option - references
- ] options - use layout page - creates structure of page, includes navigation, header, footer, similar to forms 'master' page or php includes,
- [00:00] example
- ] albums controller, creates the controller
- ] creates a folder "Albums" in views
- ] creates the basic views - ] create, ] delete, ] edit, ] details, ] index
- ( app demo now has a "private storeContect db = , where did that come from? 'its going to EF to get the data)
- *] you are in control, a controller is a class, a controller action is a method, all it needs to do is get a class that it can return to the view
- ?] repo pattern - seperating out the data access - i call a view, view returns the data
- ] controller PASSES data to view,
- ] return View(db.ToList())
- [22:00] a look at the generated index file generated by the Add Controller scaffolding
- ] uses a table , standard html table code to present table, except for some razor HTML.methods that used the passed in data model
- >] HTML.DisplayNameFor(model => model.Title)
- >] foreach (var item in model){
- <tr>
- <td>
- HTML.DisplayFor(modelItem => item.Title )
- </td>
- <td>
- HTML.ActionLink(Edit, Edit, new {id=item.albumID})
- HTML.ActionLink(Delete, Delete, new {id=item.albumID})
- HTML.ActionLink(Details, Details, new {id=item.albumID})
- <td>
- ] questions from crowd on how to make a data grid, see above, that is your "data grid"
- ] displaying date, everyone has done, looking for examples,libraries to make it easier,faster,prettier, look on codeplex, ...
- ] REVIEW - simple class, didnt have to write the controller, didnt have to write the views code,
- *] scaffolding is a 1x thing - you dont edit a scaffolded file and then rescaffold, once the files are generated they are yours.
- ] vs Web Forms where code is being generated at runtime, here the code is being generated at design time
- ] scaffolding is generating a fair bit of code, example Forms
- ] scaffolding is extensible
- [30:00] Entity Framework(EF)
- ] EF - object relational mapper(ORM) that enables .net developers to work with relational data using domain specific objects. It elminates the need for most of the data access code that developers usually need to write.
- ] EF is an open source project - backed by msft asp.net development team, you can watch code being checked in, submit issues, review issues, code
- ] context - dealings with the db state, understands multiple tables, foreign key relationships,
- ] example - mvcAlbums store DB Context
- ] public class storeContext : dbContext
- ] public DbSet<Review> Reviews {get; set;}
- ] public DbSet<Album> Albums {get; set;}
- ] public DbSet<Artist> Artists {get; set;}
- ] DbSet and DbContext - do a lot of stuff, collections classes that are smart, they understand db stuff
- ] EF is a way, for your controllers to get data and pass data into your views, you dont have to use EF, it is built into MVC, as one of the scaffolding options,
- ] you dont have to use EF, or you have to use code first, you can use it
- [34:00] EF - relations and foriegn keys
- ] automatically done for you, set your ID and a virtual and it will automatically
- ] talking about inside tips and tricks - adding the int ID field even tho ...
- ] ....
- [36:30] EF - seed methods
- ] the idea is to make it easier, to insert data, as your creating your application
- ] example @github
- ] method adds a bunch of sample data, newing up data AND inserting it
- ] handy feature of EF, the ability to seed data as application starts up
- [38:00] EF - migrations
- ] over time you may want to change your database
- ] add a new property to model, db needs to be in synch
- ] ex album model adds new property, copright
- ] migrations - in code, setup the steps, how to get from point A to point B
- ] removed migrations,
- ] has both an UP and a DOWN method
- [40:00] Visual Studio Web Tools (VS WT)
- ] some really cool new stuff,
- ] if your NOT really comfortable with html/css
- ] VS is a really good front end web editor
- ] when viewing code in your browser you can highlight an element and the VS source code that generates that element will also be highlight - makes it easy to track down where is your code (coming from/generated)
- ] ex use inspect element feature of browser, highlights the area in VS where the code is generated
- [43:00] edit your source code files,
- ] example - directly edit source file (example html, css)
- ] those changes are pushed back in into the VS IDE source and all connected browsers
- ] TEST in browser(ie) doesnt work
- *] he has special toolbar in browser, i am not seeing it on my, maybe some extension like browserlink needs to be added,
- ] 2 moving parts - ] vs web essentials ] browserlink
- ] installed ] vs web essentials(17.9MB), ]
- ] auto synch option on f12 tools
- ] can also edit .css styles for elements in your browser and the changes are pushed back into your source code
- ] unused CSS - feature - tracks classes that may not be used
- ] VS TIP WE div.className TAB TAB- will generate a div tag with the given classname
- ] VS TIP WE ul>*5 - auto generates a ul with 5 items
- ] VS TIP WE video. TAB TAB generates video tag
- ] VS TIP WE .css - ex background-color. - has color picker, shows colors, has color-selector option, ...
- ] VS TIP WE - these are just the tip of the iceberg, lots of web editing functionality built into VS, more will be covered in the Bootstrap Lesson(# #)
- [53:00] REVIEW
- ] Browser Link -
- ] Zen Coding -
- ] Intellisense ( jquery, angular, knockout, ... ) -
- ] VS Web Essentials - extension -
- ] Side Waffle - extension - if your having a burger, you might want a waffle on the side, a way to get delicous side dishes into your application, example add ( jshint, angularjs, chrome extension) any kind of we file, ] brings it in, setup the right way ] right click, add new plugin, select
- ] Scaffolding - how scaffolding is using models to generate controllers and views
- ] EF - going into my db, connecting my db to my models
- ] VS Web Tools - helping you if your not comfortable with HTML or if your, automating a lot of
- ] next lesson is on ___
[HOW-TO]
- ] # 5050 - my project - guide to asp.net - MVC
- ] # # -
[REFERENCE]
- ] # 5359 - overview series - ] reference section ] to-do, ] done
quiz
> Which two statements about Models in ASP.NET MVC applications are true?
model binds methods in the controller to forms in the ui
model automatically creates ui elements
model determines which controller ot use (
model determines which pages to display ( controller )
Which keyboard shortcut will display the Solution Explorer pane in Visual Studio?
x] > You are creating a Controller. Which two statements are true?
- controller can operate asynch
- controller can create js libraries to run client side code
A. You must specify a Model for the Controller.
B. The Controller can operate asynchronously.
C. The Controller can create JavaScript libraries to run client-side code.
D. You must specify a data context for the Controller.
>Which object does the data context connect the application with?
>You plan to use scaffolding. You need to choose a Controller type that will NOT require you to specify a Model. Which Controller type should you use?
quiz.results = 4/5