logo

Razor Syntax and ASP.NET MVC Layout Pages - Lab 8

   

Added on  2019-10-18

7 Pages1183 Words491 Views
Algonquin College, School of Advanced TechnologyCST8256 Web Programming Language ILab 8Objective1.Understand and use Razor syntax2.Use ASP.NET MVC layout pages.3.Use model and ViewBag to passing objects from controllers to views4.Use asp tag-helpers5.Use model data binding to passing objects from views to controllers.Due Date See Brightspace for the due date. To earn 5 points, you are required:1.Complete the lab as required.2.Demonstrate your lab work during the lab sessions. Preparation1.Download Lab8Resources.zip from Brightspace. Unzip the files to get the following files:_ACLayout.cshtml – A layout to be used for all pages in this labAC.png – A logo required by _ACLayout pageTopMenuItem.cs – The object model for the Top Menu in _ACLayout 2.Continue working on your lab 7. Open lab 7 solution/project.Add _ACLayout.cshtml to the folder Views > Shared by right click Sharedfolder and select Add > Existing Item ...In the same way add AC.png to the folder wwwroot > imagesCreate a subfolder MenuModel inside Models folder and add TopMenuItem.csto the folder.CST8256 Web Programming Language IPage 1
Razor Syntax and ASP.NET MVC Layout Pages - Lab 8_1
Algonquin College, School of Advanced Technology3.Generate CRUD code for entitiesIn the same way as lab 7, generate MVC Controller with views, using Entity Framework for entity Students, Employees and AcademicRecords. After completion, the lab solution should look as following:CST8256 Web Programming Language IPage 2
Razor Syntax and ASP.NET MVC Layout Pages - Lab 8_2
Algonquin College, School of Advanced TechnologyRequirementsThe first thing you do with a generated code is to clean it up; remove the parts you do notneed. For Home controllers and associated views, we only need the Index action and its associated Index view. You can delete the other generated actions and views. Function as landing “page”, the Home/Index view generally servers as the introduction page to the application and provides links to the other functions of the application. For simplicity, you can replace the content of Home/Index view with the following:<h1>Academic Records Management System</h1>1.Use _ACLayout pageTo use _ACLayout page in a view, you can put the following code block at the beginning of the View.@{ Layout = "_ACLayout";}Hint: If all views in a project use the same layout (such is the case for most web applications), you can put the above code section in _ViewStart.cshtml. Razor Engine will run the code in _ViewStart.cshtml first before interpreting any view in the project.2.Set up Top Menu_ACLayout receives a list of TopMenuItem objects via ViewBag.TopMenu. TopMenuItem class (in Models/MenuModel folder) defines a menu item on top menu bar as: publicclassTopMenuItem{publicstring AspArea { get; set; }publicstring AspController { get; set; }publicstring AspAction { get; set; }publicstring DisplayText { get; set; }}The property names are self-explanatory, they specifies the menu display text, the controller and the action the menu item links (you can ignore AspArea property).CST8256 Web Programming Language IPage 3
Razor Syntax and ASP.NET MVC Layout Pages - Lab 8_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Java Programming with Spring Boot Framework
|5
|580
|442