Однако, когда я перейду к /книгам < /code>, страница рендеры, но нет книг.
Код: Выделить всё
Models/Book.csКод: Выделить всё
public class Book
{
public int Id { get; set; }
public string Title { get; set; }
public string Author { get; set; }
}
< /code>
Pages/Books/Index.cshtml.csКод: Выделить всё
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using MyApp.Data;
public class IndexModel : PageModel
{
private readonly MyAppContext _context;
public IndexModel(MyAppContext context)
{
_context = context;
}
public IList Books { get; set; }
public void OnGet()
{
var books = _context.Books.ToList();
}
}
< /code>
Pages/Books/Index.cshtmlКод: Выделить всё
@page
@model IndexModel
@{
ViewData["Title"] = "Book List";
}
Book List
[list]
@foreach (var book in Model.Books)
{
[*]@book.Title by @book.Author
}
[/list]
< /code>
I expected the list of books to appear on the page, but nothing is shown. The page loads fine without any errors.
I confirmed the database is populated using DB Browser, restarted the development server, and double-checked the model and context classes. Still, no data is rendered on the page.
I want the /BooksПодробнее здесь: https://stackoverflow.com/questions/797 ... they-exist
Мобильная версия