Home > front end >  Populate a model and access it anywhere on the app
Populate a model and access it anywhere on the app

Time:04-18

I'm fairly new to razor pages Asp.Net MVC Razor pages, I created a model with the user fields and wanted to fill it with data once i logged in and access that same data in other pages by calling on the model instead of making another db call

This is my code currently

Model:

 public class Utilizador
{
    [Key]
    public int id { get; set; }

    [Required, MaxLength(100)]
    public string username { get; set; }

    [Required, MaxLength(100)]
    public string email { get; set; }

    [Required, MaxLength(100)]
    public string password { get; set; }

   
}

then i added a sigleton to Program.cs

builder.Services.AddSingleton<Utilizador>();

CodePudding user response:

You could try with EF Core,the official document:

enter image description here

enter image description here

enter image description here

Directly read the data stored in the session in Test2:

enter image description here

  • Related