13.10. Exercises: Razor Views¶
In this chapter, we started working on an application for tracking various coding events around town.
13.10.1. Getting Started¶
Open up your
CodingEvents project in Visual Studio. Create and checkout a new branch to
complete these exercises.
The code you start with should roughly resemble this branch. If you have been coding along with the video lessons, you’re probably in good shape.
As always, give the branch a useful name, like
Now, let’s add descriptions to our events.
13.10.2. Expanding our Events Schedule¶
In the video lessons, we learned how to use templates to display the elements in a static list called
Events. Let’s convert our
Eventslist to a
Dictionary. The structure of a dictionary enables us to add descriptions to our events. You’ll need to think about what data types the event name and description will be.
If you need to refresh your memory on dictionaries, refer to this page.
Events/Add.cshtmltemplate with a new field for a user to submit an event description.
You’ll want to also add some
labeltags to your form to let the user know what data they are entering.
EventsController.cs, add the description parameter to the
NewEventaction method and within the method, add the new event key/value pair to the
Whatever value you provided in the
nameattribute of your new description field is the name of the parameter.
Events/Index.cshtml. Replace the
tableto display event names and descriptions.
_Layout.cshtmlto display links for the Coding Events app (only