【发布时间】:2020-06-05 13:24:15
【问题描述】:
我一直在尝试开始使用 ASP.NET Core 和 Entity Framework Core,最近为它创建了一个 Web 项目。我在此文件中收到 3 个错误,其中 2 个是相同的特定错误。
错误上面标有注释。
错误 #1:
无法将方法组“DeleteTransaction”转换为非委托类型“对象”。您是否打算调用该方法?
错误 #2:
无法将类型“字符串”隐式转换为“EFDataAccessLibrary.Models.DiscInfo”
代码:
@page "/DeleteEmployee/{CurrentID}"
@using EFDataAccessLibrary.Models;
@inject DiscService ObjDiscService
@inject NavigationManager NavigationManager
<h2>Delete Transaction</h2>
<hr />
<h3>Are you sure?</h3>
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label>Employee ID:</label>
<label>@objDisc.Id</label>
</div>
<div class="form-group">
<label>Category:</label>
<label>@objDisc.Category</label>
</div>
<div class="form-group">
<label>Description:</label>
<label>@objDisc.Description</label>
</div>
<div class="form-group">
<label>Amount:</label>
<label>@objDisc.Amount</label>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
// Error 1
<button class="btn btn-danger" @onclick="@DeleteTransaction">Delete</button>
// Error 1
<input type="button" class="btn btn-primary" @onclick="@Cancel" value="Cancel" />
</div>
</div>
</div>
@code {
[Parameter]
public string CurrentID { get; set; }
DiscInfo objDisc = new DiscInfo();
protected override async Task OnInitializedAsync()
{ // Error 2
objDisc = await Task.Run(() => ObjDiscService.DeleteTransactionDisc((objDisc));
}
protected void DeleteTransaction()
{
ObjDiscService.DeleteTransactionDisc(objDisc);
NavigationManager.NavigateTo("disc");
}
void Cancel()
{
NavigationManager.NavigateTo("disc");
}
}
如果有人想整体查看该项目,或者如果您认为另一个文件中存在导致此问题的问题,我已将该项目发布到 GitHub。
【问题讨论】:
标签: c# asp.net-core entity-framework-core crud