Advertisement
-
Our first view
Recall that the ASP.NET MVC Framework uses a convention for locating views. The
convention is to find a .aspx file in a directory tree that matches /Views/controllername/
actionname.aspx. In our next example, we’ll modify our controller by calling a
method on the Controller base class called View(). We’ll set the model, which is a
string with the text “Hello World”, to an entry in the ViewDataDictionary object on
the ViewData property of the Controller base class. This ViewDataDictionary
instance will be forwarded to the view. Although ViewData is a ViewDataDictionary
we recommend you depend only on the IDictionaryinterface if
you’re replacing the view engine. View engines will be discussed in more detail in
chapter 4. In listing 1.9, we see that our action returns ActionResult instead of
string. After an action method returns, the ActionResult executes to perform the
appropriate behavior, which is rendering a view in this case. Examine listing 1.9 for
the current implementation of our controller. ViewData contains the object that will
be forwarded on to the view. The View() method also supports passing a single object
to the view that is then accessible via ViewData.Model, which we’ll explore later.
more
Subscribe to:
Comments (Atom)