Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning ASP.NET Core MVC Programming

You're reading from  Learning ASP.NET Core MVC Programming

Product type Book
Published in Nov 2016
Publisher Packt
ISBN-13 9781786463838
Pages 326 pages
Edition 1st Edition
Languages
Authors (2):
Mugilan T. S. Ragupathi Mugilan T. S. Ragupathi
Profile icon Mugilan T. S. Ragupathi
Anuraj Parameswaran Anuraj Parameswaran
Profile icon Anuraj Parameswaran
View More author details

Table of Contents (18) Chapters

Learning ASP.NET Core MVC Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Introduction to ASP.NET Core 2. Setting Up the Environment 3. Controllers 4. Views 5. Models 6. Validation 7. Routing 8. Beautifying ASP.NET MVC Applications with Bootstrap 9. Deployment of ASP.NET Core Application 10. Building HTTP-based Web Services Using ASP.NET Web API 11. Improving Performance of an ASP.NET Core Application 12. ASP.NET Core Identity

Adding Views


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

Let us create a new action method by the name, Index2:

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

Now, we have created the action method that returns a View. But we still have not added the View for the same. By convention, ASP.NET MVC would try to search for our View in the folder Views\{ControllerName}\{ActionMethod.cshtml}. 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. Only the prefix is 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, let us create a folder...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}