This series will be more detailed than MVC4. Mvc4 record or not recorded things will also be mentioned here.
Controller
Automatic assembly:
General automatic Assembly is useful when adding
View:
The view returned by the controller is actually some static HTML. The dynamic is not good, transfer a small amount of data from the controller, the simplest use VIEWBAG. Applies only to small amounts of data.
Strongly typed views
Start learning when you think ViewBag is OK, one to write the project when you will feel viewbag very inconvenient.
ViewBag of the poor
Because ViewBag is dynamically parsed, it needs to go down every time it's used.
Upgrade a little, but this time you can not take the output properties, because it is dynamic parsing, as long as the runtime will be resolved, will be error . Dynamic=var
At this time, we need a strong type to improve the above deficiencies .
Controller to view value: The difference between ViewBag and ViewData
ViewData is more like a special dictionary type.
The VIEWBAG is dynamically parsed.
View Model
Add a View
Razor View Engine
Code expression
The core conversion character in Razor is @, and razor is smart to make it very popular. Smart: Most of the characters can be judged by their own properties or displayed.
HTML encoding avoids XSS attacks, which are detailed in later articles
Razor Syntax Examples
Layout is equivalent to the master page in Web Forms
① Create a new MVC5 layout page sitelayoutpage.cshtml layout page can be thought of as a special view.
② Create a view associated with it
Index page We made a good understanding of the correlation, the test page we did not do the correlation can also be related. That's because there's a _viewstart.cshtml page .
Declare the footer section in index only and no longer declare it in test
Open test and you'll get an error.
Specify partial views
① Create a method that returns a partial view
② adding views
Partial views are generally used to make local updates very useful. It is very common to put HTML into a local view and then use Ajax for updates.
Index page:
Layout page:
MVC5 controller, view simple description