Display Data in Asp.net Core

Yusuf 691 Reputation points
2021-06-07T03:01:43.96+00:00

Hi
I am new to ASP.NET Core and I want to display data in main Index.cshtml page
I followed these steps:

• Create New Project > ASP.NET Core Web App

102740-1.png

• Project > Add > New Folder > "Model"
• "Model" > Add > Class > "Book"

using System;  
using System.Collections.Generic;  
using System.ComponentModel.DataAnnotations;  
using System.Linq;  
using System.Threading.Tasks;  
  
namespace WebApplication8.Model  
{  
    public class Book  
    {  
        [Key]  
        public int id { get; set; }  
        public string title { get; set; }  
    }  
}  
  

• Pages > Add > New Folder > "Books"

• "Books" > Add > New Scaffolded Item > Razor Pages using Entity Framework (KRUD)

102843-2.png

• Tools > NuGet Pacage Manager > Package Manager Console

PM> Add-Migration InitialCreate -Context WebApplication8.Data.WebApplication8Context  
PM> Update-Database -Context WebApplication8.Data.WebApplication8Context  

• Change IIS Express to WebApplication8 and Run

• Add some data to https://localhost:5001/Books

I stopped here, and now I'm trying to view list of books on the home page.

Thanks

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,199 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,280 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,289 questions
{count} votes

Accepted answer
  1. Duane Arnold 3,216 Reputation points
    2021-06-07T13:57:57.41+00:00

    IMHO you need to understand the following:

    1) understand the models used in MVC...
    https://deviq.com/terms/kinds-of-models

    2) understand how to use a viewmodel
    https://www.dotnettricks.com/learn/mvc/understanding-viewmodel-in-aspnet-mvc

    3) understand SoC and MVC
    https://en.wikipedia.org/wiki/Separation_of_concerns
    https://www.c-sharpcorner.com/UploadFile/56fb14/understanding-separation-of-concern-and-Asp-Net-mvc/
    https://learn.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/architectural-principles

    4) understand clean coding and dependency injection
    https://learn.microsoft.com/en-us/archive/msdn-magazine/2016/may/asp-net-writing-clean-code-in-asp-net-core-with-dependency-injection

    5) understand to keep the controller thin, which is being talked about in one of the last topics in the link about Understanding Models.
    https://learn.microsoft.com/en-us/aspnet/mvc/overview/older-versions-1/overview/understanding-models-views-and-controllers-cs

    You should understand the principles of using MVC, becuase the MVC pipeline is being used in a Razor page project the Visual Studio project architecture is the same as a MVC project.

    continued....


0 additional answers

Sort by: Most helpful