Now that we have the form created we can create a page where
we can display the posted results. I am again going to try to keep this as
simple as possible. How to render data on a view is within the scope of another
article and not this one.
We obviously need to go and create a new view, which is just
an "aspx" file in the correct folder. We will later be passing data
to this view so that it can be rendered as content for the user to see. This is
a fairly easy process, so I will try to make things quick.
Create the View Page
First, just right click on the Home folder since we
specified earlier we were going to make this action part of the Home
controller. Then you will select the "Add" submenu and from within
that submenu you should see "View." Click on that option.
Figure 4: Add new view context menu
From here you should get a small window to fill in the
details about the view you are going to create. This is just a little helper to
make the view creation a little bit faster and easier. You obviously could have
just created the file by hand, but some of the common tasks are listed here and
we will be taking advantage of the master page section of the Add View window.
Figure 5: Add View window
On this window we made sure to name the View something that
would make sense considering the action we used earlier in our HTML form. We
also selected a master page. I might have used a strongly-typed view, but in
this demonstration we have not defined any classes yet. Without any classes we
do not have a type to set, so there is no reason to use that feature.
Once you click the Add button, the file will be created and
opened for you. Now we can start adding in our rendered content. For this simple
little demo we will just write out our values that we receive on the page, so
we will need to write out our "First Name," "Middle Name,"
and "Last Name." Before we can actually see this, we will need to
create a controller. These are not the same as the pages on web forms. We need
to have a controller action show us this view before we can see it.
Listing 2: Display View Markup
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>DisplayUserData</h2>
First Name: <%= ViewData["FirstName"] %> <br />
Middle Name: <%= ViewData["MiddleName"] %> <br />
Last Name: <%= ViewData["LastName"] %>
<span style='background:yellow'> </span>
</asp:Content>