Select the menu links RazorPagesMovie, Home, and Privacy. When the lambda expression is evaluated, for example, with => item.Title), the model's property values are evaluated. That means there is no access violation when model, model.Movie, or model.Movie is null or empty. The lambda expression is inspected rather than evaluated. The DisplayNameFor HTML Helper inspects the Title property referenced in the lambda expression to determine the display name. The model is used in the and HTML Helpers on the page.Įxamine the lambda expression used in the following HTML Helper: => ) In the preceding example, the line makes the PageModel-derived class available to the Razor Page. The directive specifies the type of the model passed to the Razor Page. and are examples of transitioning into Razor-specific markup. must be the first Razor directive on a page. The Razor directive makes the file an MVC action, which means that it can handle requests. When an symbol is followed by a Razor reserved keyword, it transitions into Razor-specific markup, otherwise it transitions into C#. Razor can transition from HTML into C# or into Razor-specific markup. For example, the Pages/Movies/ OnPostAsync method: public async Task OnPostAsync()Įxamine the Pages/Movies/Index.cshtml Razor Page: = "Index" Ĭreate => => => => (var item in Model.Movie) => => => => item.Price) When the return type is IActionResult or Task, a return statement must be provided.
For example the Privacy Page: public class PrivacyModel : PageModel When OnGet returns void or OnGetAsync returns Task, no return statement is used. In this case, OnGetAsync gets a list of movies and displays them. On a Razor Page, OnGetAsync or OnGet is called to initialize the state of the page. When a request is made for the page, the OnGetAsync method returns a list of movies to the Razor Page.
PAGES FOR MAC TUTORIAL 2015 CODE
See Asynchronous code for more information on asynchronous programming with Entity Framework. The constructor uses dependency injection to add the RazorPagesMovieContext to the page: public class IndexModel : PageModel By convention, the PageModel-derived class is named Model. The Create, Delete, Details, and Edit pagesĮxamine the Pages/Movies/ Page Model: // Unused usings removed.