gpt4 book ai didi

ajax - ASP .NET Core Razor : Model bound complex types must not be abstract or value types and must have a parameterless constructor

转载 作者:行者123 更新时间:2023-12-04 01:44:23 28 4
gpt4 key购买 nike

如果我的模型中有这样的属性:

    [BindProperty]
public IPagedList<Product> Products { get; set; }

然后当我尝试发布时,我收到此错误:
An unhandled exception occurred while processing the request.
InvalidOperationException: Could not create an instance of type 'X.PagedList.IPagedList`1[Data.Models.Product, Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'. Model bound complex types must not be abstract or value types and must have a parameterless constructor. Alternatively, set the 'Products' property to a non-null value in the 'Areas.Catalog.Pages.ProductListModel' constructor.

错误说我可以在构造函数中将属性设置为非空值,所以我尝试在构造函数中执行此操作:
Products = new PagedList<Product>(Enumerable.Empty<Product>(), 1, 10);

但我得到同样的错误。

最佳答案

当我删除 [BindProperty] 时,它可以工作。我的印象是我需要绑定(bind) Razor 页面上的属性,但我猜不是?

关于ajax - ASP .NET Core Razor : Model bound complex types must not be abstract or value types and must have a parameterless constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55926657/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com