在 ASP.NET Core 中向 Razor Pages 应用显示模型
2021-04-30 14:27
                         标签:release   ase   remove   基本   显示   models   options   tco   serve    以下是实现也一个asp.net core Razor Pages的基本步骤 1、定义模型元素 2、创建数据库上下文 3、将数据库上下文添加到服务中 4、Razor Pages页面代码管理 5、模型和页面关联 
    Create New
   在 ASP.NET Core 中向 Razor Pages 应用显示模型 标签:release   ase   remove   基本   显示   models   options   tco   serve    原文地址:https://www.cnblogs.com/minhost/p/12153059.html
using System;
using System.ComponentModel.DataAnnotations;
namespace RazorPagesMovie.Models
{
    public class Movie
    {
        public int ID { get; set; }
        public string Title { get; set; }
        [DataType(DataType.Date)]
        public DateTime ReleaseDate { get; set; }
        public string Genre { get; set; }
        public decimal Price { get; set; }
    }
}


using Microsoft.EntityFrameworkCore;
namespace RazorPagesMovie.Models
{
    public class RazorPagesMovieContext : DbContext
    {
        public RazorPagesMovieContext (DbContextOptions


public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();
    services.AddDbContext


// Unused usings removed.
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using RazorPagesMovie.Models;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace RazorPagesMovie.Pages.Movies
{
    public class IndexModel : PageModel
    {
        private readonly RazorPagesMovie.Data.RazorPagesMovieContext _context;
        public IndexModel(RazorPagesMovie.Data.RazorPagesMovieContext context)
        {
            _context = context;
        }
        public IList


@page
@model RazorPagesMovie.Pages.Movies.IndexModel
@{
    ViewData["Title"] = "Index";
}
Index
 
@foreach (var item in Model.Movie) {
        
                @Html.DisplayNameFor(model => model.Movie[0].Title)
             
            
                @Html.DisplayNameFor(model => model.Movie[0].ReleaseDate)
             
            
                @Html.DisplayNameFor(model => model.Movie[0].Genre)
             
            
                @Html.DisplayNameFor(model => model.Movie[0].Price)
             
            
         
 
}
    
                @Html.DisplayFor(modelItem => item.Title)
             
            
                @Html.DisplayFor(modelItem => item.ReleaseDate)
             
            
                @Html.DisplayFor(modelItem => item.Genre)
             
            
                @Html.DisplayFor(modelItem => item.Price)
             
            
                Edit |
                Details |
                Delete
             
        
文章标题:在 ASP.NET Core 中向 Razor Pages 应用显示模型
文章链接:http://soscw.com/index.php/essay/80427.html