Bug tracker: Create the ProjectMaster view
The ProjectMaster view displays the list of available projects. The view is represented by a Razor web page. To create the view:
- In Visual Studio, navigate to the Areas BugTracker Views Project folder and create a new file with the cshtml extension.
Name the class ProjectMaster.
- Add using statements to the following namespaces:
Define the type of the Model property.
Use the same type as the type of the data that you passed as the model argument to the View method in the project controller.
Create an HTML entry for each of the projects in the query:
- Create an unordered list element.
- Inside the tag of the list, use foreach and create a list item element for each project.
- As content of the list item element, create a hyperlink by using the ActionLink method.
This link must navigate to the view containing the list of bugs for the project.
- Pass the Title of the project as the linkText argument.
- Pass Index as the actionName argument.
- Pass Bug as the controllerName argument.
- Create an anonymous type containing the ID parameter and pass it as the routeValues argument.
- As the htmlAttributes argument pass null.
The generated URL will look similar to this one: http://localhost/Bug/Index/EAC1A302-76E3-4E0E-B314-B56CB76E6562. This means that the Index action in the BugController class will be executed and the route values will contain the ID of the respective project.
GITHUB EXAMPLE: For more information about the content of the file, see the ProjectMaster.cshtml file of the downloaded sample project.