Views
As we learned from previous chapter, returning content directly from the controller action method is not ideal.
It is a simple task to returning content from the view model. Let's get in code.
Before:
public ActionResult Detail()
{
if (DateTime.Today.DayOfWeek == DayOfWeek.Tuesday)
{
return Redirect("/");
}
return Content("Hello from ComicBookController");
}
Let's returning a view not a string from Detail() function.
After:
public ActionResult Detail()
{
return View();
}
Run it on Google Chrome and PUFFF! It shows an error.
Why? We are returning the view that not being defined earlier.