【发布时间】:2022-08-16 22:39:27
【问题描述】:
我正在使用这个模态组件:https://blazorrepl.telerik.com/wwkzbjaz45yvMAC202
这是代码的样子:
<h4>Contact List</h4>
<table>
<thead>
<th>Name</th>
<th>Email</th>
</thead>
<tbody>
@foreach (var item in contacts!)
{
<tr>
<td>@item.Name</td>
<td>@item.Email</td>
<button @onclick= \"@(()=>OnConfirm(item.Name))\">Delete</button>
</tr>
}
</tbody>
</table>
<ModalDialog OnDelete=\"DeleteContact\" @ref=\"modalDialog\"></ModalDialog>
@code {
private ModalDialog modalDialog;
private bool showContacts = true;
private List<Contact>? contacts = null;
protected override void OnInitialized()
{
contacts = new List<Contact>(){
new Contact(){Name=\"John \",Email=\"john@example.com\"},
new Contact(){Name=\"Bob\",Email=\"bob@example.com\"},
new Contact(){Name=\"Bill\",Email=\"bill@example.com\"}
};
base.OnInitialized();
}
public void OnConfirm(string name){
modalDialog.Name=name;
modalDialog.ChildContent=$\"Do you want to delete {name}\";
modalDialog.Show();
}
public void DeleteContact(){
var c=contacts?.Find(x=>x.Name==modalDialog.Name);
contacts.Remove(c);
StateHasChanged();
modalDialog.Close();
}
}
这就是您启动组件的方式:
<ModalDialog OnDelete=\"DeleteContact\" @ref=\"modalDialog\"></ModalDialog>
事实上,它工作得很好,直到我尝试在
<ModalDialog OnDelete=\"DeleteContact\" @ref=\"modalDialog\">
<div> hello </div>
<ModalDialog>
我收到以下错误:
Error CS1660 Cannot convert lambda expression to type \'string\' because it is not a delegate type Inest C:\\....\\Microsoft.NET.Sdk.Razor.SourceGenerators\\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\\Components_TestedBy_razor.g.cs 222 Active