Azure.NET MVC核心应用程序:找不到适用于模型类型的构造函数



我正在尝试使用我在Index.cshtml文件(位于Pages文件夹中(中创建的模型(RoleAssignmentRecord(。下面是我的Index.chtml代码:

@page
@using AccessChangeMonitoringUI.Models
@model RoleAssignmentRecord
<div class="text-center">
<h1 class="display-4">OneAuthZ Change Monitoring</h1>
<p>View OneAuthZ role change history and acknowledge role changes.</p>
@using (Html.BeginForm("RoleAssignmentController", "TestForm", FormMethod.Get))
{
<label>Test Form</label>
<input type="submit" name="submit" value="Submit" />
}
</div>

以下是我在Models文件夹中的RoleAssignmentRecord代码:

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace AccessChangeMonitoringUI.Models
{
public class RoleAssignmentRecord
{
[JsonProperty(PropertyName = "id")]
string id { get; set; }
[JsonProperty(PropertyName = "RoleAssignmentId")]
string roleId { get; set; }
List<RoleAssignmentChange> changeHistory { get; set; }
RoleAssignment currentRow { get; set; }
RoleAssignmentRecord(RoleAssignment currentRow, List<RoleAssignmentChange> changeHistory)
{
this.id = currentRow.Id;
this.roleId = currentRow.Id;
this.currentRow = currentRow;
this.changeHistory = changeHistory;
}
}
}

然而,当我运行应用程序时,我收到以下错误:

InvalidOperationException:适用于类型的构造函数"AccessChangeMonitoringUI.Models.RoleAssignmentRecord"不能为位于。确保类型是具体的,并且服务已注册公共构造函数的所有参数。

考虑到我确实有RoleAssignmentRecord的构造函数,这似乎很奇怪

请注意,如果不在构造函数中使用访问修饰符,默认情况下它仍然是私有的但是,private修饰符通常被显式地使用,以表明类不能被实例化。

它应该是公共,否则DI无法访问它:

public RoleAssignmentRecord(RoleAssignment currentRow, List<RoleAssignmentChange> changeHistory)
{
this.id = currentRow.Id;
this.roleId = currentRow.Id;
this.currentRow = currentRow;
this.changeHistory = changeHistory;
}

最新更新