Microsoft Official Course: Controllers
Microsoft Official Course: Controllers
Module04
if (firstPhoto != null) {
} else {
return HttpNotFound();
}
}
Using Parameters
The DefaultModelBinder obtains the Title parameter from the query string and
passes it to the title parameter of the GetPhotoByTitle method, because the names
match.
http://www.adventureworks.com/photo/getphotobytitle?title=myfirstphoto
DefaultModelBinder
Adding Information:
Retrieving Information:
<p>
The message of the day is: @ViewBag.Message
</p>
<p>
The time on the server is: @ViewBag.ServerTime.ToString()
</p>
Demonstration: How to Create a Controller
You have been asked to add a controller to the photo sharing application that
corresponds to the Photo model class that you have created in an earlier
module. The controller should include actions that respond when users upload
photos, list all photos, display a single photo, and delete photos from the
application. You should also add an action that returns the photo as a .jpg file
to show on a webpage.
The members of your development team are new to ASP.NET MVC and they
find the use of controller actions confusing. Therefore, you need to help them
by adding a component that displays action parameters in the Visual Studio
Output window whenever an action runs. You will add an action filter to
achieve this.
Note: The controllers and views that you have added in Lab 2 were to test
your new model classes. They have been removed from the project to create
the actual controllers. You will create temporary views to test these controllers
at the end of this lab.
Lab Review
Review Question(s)
• Best Practice