Book Image

ASP.NET Core Essentials

By : Shahed Chowdhuri
Book Image

ASP.NET Core Essentials

By: Shahed Chowdhuri

Overview of this book

<p>ASP.NET Core is the latest collection of Microsoft’s web application development technologies. When you’re trying to reach a broad spectrum of users with a robust web application, ASP.NET Core is there to help you build that application. With the ability to cater to users on desktop, tablet, or smartphone platforms, you can put together a solution that works well anywhere.</p> <p>This book is what you need to get started developing ASP.NET Core applications was quickly as possible; starting by introducing the software and how it can be used in today’s modern world of web applications and smartphone apps. Walking you through the benefits of a Web API to support both applications and mobile apps to give you a solid understanding of the tech to build upon as you see what ASP.NET Core can do for you.</p> <p>The book wraps up with practical guidelines for the use of database technologies, unit tests, security best practices, and cloud deployments for the real world.</p>
Table of Contents (15 chapters)
ASP.NET Core Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Designing models and ViewModels


Instead of passing around individual values one by one from controllers to views, you can use a model to store a set of data. The controller is responsible for updating the model, which can be associated with a view to get its data.

Creating models

A model is just a class file with a .cs file extension. In the Solution Explorer panel, you can add new model class files to the Models folder. You may have noticed that there are choices available for MVC Controller class and MVC View page, but none for the Model class.

To create a model class, we can select the Class option when adding a new item as follows:

  1. In Solution Explorer, right-click the Models folder, and click Add | New Item.

  2. In the Add New Item dialog, select Class under Code.

  3. Name the file Human.cs to create a new model.

  4. Verify that you have an empty class named Human.

Add the following fields to the Human class:

public class Human 
{ 
    public int ID { get; set; } 
    public string SocialSecurityNumber...