当我在我的cshtml文件中使用@model ExternalProject.Model
并在该模型上执行填充时,我在加载页面时会继续收到以下错误:
Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
用完了选项,我尝试在这个项目内部制作一个模型并且它有效。是否真的不可能使用外部DLL作为标记助手?
使用外部模型
public class EmployeeEntity
{
public EmployeeEntity()
{
DailyAttendances = new HashSet<DailyAttendanceEntity>();
Loans = new HashSet<LoanEntity>();
}
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName { get { return FirstName + " " + LastName; } }
public double TimeInTime { get; set; }
public string ContactNumber { get; set; }
public string Address { get; set; }
public bool IsRegular { get; set; }
public string Remarks { get; set; }
public DateTime HireDate { get; set; }
public int? FingerprintId { get; set; }
public virtual ICollection<LoanEntity> Loans { get; set; }
public virtual ICollection<DailyAttendanceEntity> DailyAttendances { get; set; }
}
用于测试的内部模型
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
CSHTML文件
@using BusinessEntities;
@model EmployeeEntity
<form asp-controller="Demo" asp-action="RegisterInput" method="post">
FirstName: <input asp-for="FirstName" /> <br />
LastName: <input asp-for="LastName" /><br />
<button type="submit">Register</button>
</form>
编辑:这实际上也发生在使用HTML帮助程序时。刚刚意识到。