Book Image

ASP.NET Core 2 Fundamentals

By : Onur Gumus, Mugilan T. S. Ragupathi
Book Image

ASP.NET Core 2 Fundamentals

By: Onur Gumus, Mugilan T. S. Ragupathi

Overview of this book

The book sets the stage with an introduction to web applications and helps you build an understanding of the tried-and-true MVC architecture. You learn all about views, from what is the Razor view engine to tagging helpers. You gain insight into what models are, how to bind them, and how to migrate database using the correct model. As you get comfortable with the world of ASP.NET, you learn about validation and routing. You also learn the advanced concepts, such as designing Rest Buy (a RESTful shopping cart application), creating entities for it, and creating EF context and migrations. By the time you are done reading the book, you will be able to optimally use ASP.NET to develop, unit test, and deploy applications like a pro.
Table of Contents (14 chapters)

Adding Views


So far, we were returning a simple string from the controller. Although that explains the concept of how the Controller and action methods works, it is not of much practical use.

Let's create a new action method named, Index2:

Note

Go to https://goo.gl/UhaHyz to access the code.

public IActionResult Index2()
{
  return View(); // View for this 'Index2' action method
}

Now, we have created the action method that returns a view, but we have still not added the view. By convention, ASP.NET MVC would try to search for our view in the Views\{ControllerName}\{ActionMethod.cshtml} folder. With respect to the preceding example, it will try to search for Views\Home\Index2.cshtml. Please note that the name of the controller folder is Home, not HomeController. The prefix is only needed as per convention. As this folder structure and file are not available, you'll get a 500 Internal Server Error when you try to access this action method through the URL http://localhost:50140/Home/Index2.

So...